Copy the content of a file to the clipboard from the command line
$ xclip file.txt
Sometimes, you might need to copy to another selection, for instance:
$ xclip -selection clipboard file.txt
$ man xclip to see other selections.
If you need to install xclip run:
$ sudo apt install xclip
What is xclip?
From xclip’s repository:
xclip is a command line utility that is designed to run on any system with an X11 implementation. It provides an interface to X selections (“the clipboard”) from the command line. It can read data from standard in or a file and place it in an X selection for pasting into other X applications. xclip can also print an X selection to standard out, which can then be redirected to a file or another program.
xclip is licensed under GNU General Public License v2.0.
You can run
$ man xclip for more informations, options, examples, etc.
personal computing gnu linux command-line interface (cli) trisquel xclip