Ever felt that copy-pasting utilizing the rodent gets tiresome? Especially erstwhile you're much comfy utilizing the terminal and the keyboard, switching to the rodent tin beryllium counterproductive. The xclip bid volition assistance you enactment connected your keyboard erstwhile you privation to transcript and paste content.
What Is xclip?
xclip is simply a command-line inferior utilized connected Linux systems with an X11 implementation to interact with the X enactment (also known arsenic the clipboard). It allows you to transcript substance from files oregon modular input and marque it disposable for pasting successful different X applications. xclip tin besides people the contents of the X enactment to modular output. It has galore utile options and usage cases to explore.
Even though it sounds similar xclip is lone meant for systems that usage the X model manager. That's not the case, arsenic you'll spot however I usage it connected a Wayland system.
In this speedy guide, we'll dive heavy into however you tin usage the xclip bid to transcript contents from a file, antithetic utile options, and erstwhile it's utile to whip retired xclip. For objection purposes, I'll beryllium utilizing Ubuntu 24.04 LTS. If you're utilizing a antithetic distro, you tin inactive travel along, but you whitethorn request to tweak immoderate commands slightly.
When Is xclip Most Useful?
The champion usage lawsuit I tin deliberation of is erstwhile you privation to transcript ample files. It tin beryllium tedious to usage the rodent to support selecting lines aft lines. Quite often, agelong lines get chopped disconnected successful immoderate substance editors, specified arsenic nano. In that case, it gets adjacent much hard to prime and transcript the record content. In specified situations, xclip tin beryllium a convenient instrumentality to use. You tin transcript the record contented with a azygous bid and paste it anyplace you want.
How to Get and Use xclip
xclip usually doesn't travel pre-installed connected Linux distributions. So, successful that case, you'll person to instal it yourself. You tin either instal it utilizing your distro's bundle manager oregon get the root from its GitHub repository. For Debian, Ubuntu, and their derivatives, instal it using:
sudo apt instal xclip
If you're utilizing Red Hat, Fedora, oregon the likes, past run:
sudo dnf instal xclipFor Arch Linux and Manjaro users, use:
sudo pacman -S xclipTo corroborate the installation, you tin cheque its mentation by running:
xclip -versionThe astir basal mode to usage the xclip bid is to transcript the contented from the modular input oregon a file. For example, if you privation to transcript a file's contented to the clipboard alternatively of displaying it connected the terminal, simply tube the output to the xclip command. Let maine make a elemental record to amusement you how.
First, I'll make a trial record and enactment immoderate dummy substance successful it.
touch test.txtecho 'Demonstrating the xclip command' > test.txt
Now, to work the contents of the record and show the output connected the bid line, we usage the feline command. We'll bash the aforesaid here, but tube the output to the xclip bid similar this:
cat test.txt | xclip
The effect isn't evident here. That's due to the fact that we don't person immoderate output oregon anything. So, however bash you cognize that the transcript was successful? To show the existent clipboard content, simply run:
xclip -o
If you don't privation to transcript the contented of a circumstantial record and simply privation to enactment immoderate substance successful the clipboard, past the echo bid is helpful. We'll tube the commands successful the aforesaid mode we did earlier.
echo "I unrecorded successful the clipboard" | xclipxclip -o

You tin besides transcript contented from a record without piping the output. To bash that, walk the record sanction arsenic an argument.
xclip test.txtxclip -o
There's different mode you tin transcript record content. Here's the afloat command:
xclip -sel clip test.txt
There's a subtle quality betwixt conscionable passing the record sanction and utilizing the -sel clip option. The -sel clip enactment is really the abbreviated signifier of -selection clipboard. When you usage this option, alternatively of the X model clipboard, you interact with the strategy clipboard. So what does that mean? If you're utilizing the archetypal bid (passing lone the record name), you tin paste the copied contented utilizing the mediate fastener of your mouse. In the 2nd case, you request to paste the contented from the right-click discourse paper oregon by pressing Ctrl+Shift+v.
When copying contented from a file, sometimes you'd privation to disregard the newline character. To bash that, use:
xclip -r test.txt
Another absorbing enactment is the looping option. When you usage this option, you fundamentally archer xclip to load the contents of the record into the X11 clipboard, and fto it beryllium pasted a circumstantial fig of times into applications similar terminals oregon substance editors that work from the X enactment earlier exiting. By default, the fig is zero, truthful xclip tin instrumentality infinite requests. Here's an example:
xclip -loops 5 -verbose test.txt
Using xclip, you tin besides paste the contented to a record utilizing redirection.
touch test2.txtxclip test.txt
xclip -o > test2.txt
cat test2.txt

xclip doesn't lone transcript the contented of substance files, it tin besides transcript output from different commands. Say you privation to transcript the existent directory content. To bash so, run:
ls -la | xclipxclip -o

Besides each these, xclip besides comes with a fewer much utilities specified arsenic xclip-copyfile, xclip-pastefile, and xclip-cutfile. You tin usage these commands to transcript and determination files betwixt antithetic directories and adjacent machines. You tin larn much astir it utilizing the man page oregon -h option.
The xclip instrumentality is fantastic for speedy copy-pasting work. If you prefer utilizing the bid line and keyboard for astir things, it tin assistance you debar the rodent for faster workflows. There are galore much useful Linux commands similar this retired for you to try.