Copy file content to clipboard in terminal

If you are working in terminal/console most of your time, you may already know how to copy a file content to clipboard. But if not, here today we will explore how can we copy a file content to clipboard in terminal.



sudo pacman -S xclip


sudo apt install -y xclip


We will add an alias for it to make it easier to use.


Add it to .zshrc file in terminal.

echo "alias ccopy='xclip -sel clip <'" >> ~/.zshrc

Note: I have used ccopy as a command, you can use any. Just make sure to not use any of the current ones your system may have.

We have ccopy alias above, to use it right away without login or restart.

source ~/.zshrc


echo "alias ccopy='xclip -sel clip <'" >> ~/.bashrc

Reload .bashrc:

source ~/.bashrc


Using it is very simple.

ccopy /var/www/html/footer.php

Content of footer.php is now available in clipboard.

Let’s copy our system public ssh key to clipboard.

ccopy ~/.ssh/