xclip to simplify your workflow when working on the Linux terminal can make work more fun, exciting, and faster. This tool allows you to easily copy data from a standard input, or from one or more files and paste the data into
X application. The second command-line utility we are going to use is pipes (
|) that are standard in Unix systems. The pipe command is used to transfer the standard output of a command into standard input on another command in a unidirectional data stream (data flows from left to right).
You will need to install
xclip if you haven't already. You can run the following command to verify if it is installed:
The following commands will install
xclip on the most popular types of Linux distributions.
sudo apt install xclip
sudo yum install xclip
sudo pacman install xclip
Copy and Paste
To copy the standard output of a command to the
X clipboard as standard input all you need is to pipe the first command to
xclip with no arguments since it defaults to the
-in argument. If using a mouse, the copied standard input will be placed in the middle click.
command1 | xclip
To paste the text you just copied to a standard output, you add the
-out argument to the
xclip command or use the middle click.
Generally these two commands are used to pipe to a file or program. Let's take a look at an example of this workflow:
- Pipe the standard output of our system's uptime as standard input to the
uptime | xclip
- Print as standard output of the content copied to a new file as standard input.
xclip -o > hello.txt
- To verify if the content was added to this new file, you can print the file to a standard output with the
catcommand line utility.
Paste with Right-Click
If you preferred to have the standard output of the first command on the right-click of your mouse or
CTRL-V you can specify a selection with the
-selection argument. The selection you will need to choose is the
command1 | xclip -sel clip
command1 | xclip -sel sec
- “Cat(1) - Linux Manual Page.” Accessed October 28, 2021. https://www.man7.org/linux/man-pages/man1/cat.1.html.
- Stack Overflow. “Linux - How Can I Copy the Output of a Command Directly into My Clipboard?” Accessed October 25, 2021. https://stackoverflow.com/questions/5130968/how-can-i-copy-the-output-of-a-command-directly-into-my-clipboard.
- EDUCBA. “Linux Pipe Command | Complete Guide to Linux Pipe Command,” June 30, 2021. https://www.educba.com/linux-pipe-command/.
- Mckay, Dave. “How to Use Pipes on Linux.” How-To Geek. Accessed October 25, 2021. https://www.howtogeek.com/438882/how-to-use-pipes-on-linux/.
- ———. “What Are Stdin, Stdout, and Stderr on Linux?” How-To Geek. Accessed October 28, 2021. https://www.howtogeek.com/435903/what-are-stdin-stdout-and-stderr-on-linux/.
- “Xclip(1): CLI to X Selections - Linux Man Page.” Accessed October 28, 2021. https://linux.die.net/man/1/xclip.