xclip
is a command-line utility for interacting with the clipboard in Linux systems. It allows you to copy data to the clipboard from the command line or retrieve data from the clipboard into the terminal.
Here's how you can use it with some examples, note you can use -sel clip
for short of -selection clipboard
:
-
Copy Output of a Command to Clipboard:
ls -l | xclip -selection clipboard
-
Copy Text from a File to Clipboard:
cat file.txt | xclip -selection clipboard
-
Paste Clipboard Content to Terminal:
xclip -selection clipboard -o
-
Copy SSH Public Key to Clipboard:
cat ~/.ssh/id_rsa.pub | xclip -selection clipboard
-
Copy Output of a Command with Line Numbers:
cat file.txt | nl -ba -n ln | xclip -selection clipboard
-
Copy and Paste Text Between Two Terminals: In one terminal, copy text to the clipboard:
echo "Hello, world!" | xclip -selection clipboard
In another terminal, paste the copied text:
xclip -selection clipboard -o
Note: You might need to install xclip
using your package manager (sudo apt install xclip
on Debian-based systems, sudo yum install xclip
on Red Hat-based systems) before using it.