Sometimes it can be cumbersome to copy a large block of text from a terminal
window and this gets more awkward when pages and pages of output scroll by.
Thankfully the nifty little xsel
command line tool was built just for this!
If you don’t already have it installed, the following should get you going on a Debian-like system:
$ sudo apt-get install xsel
$ cat /etc/hosts | xsel --clipboard
The contents of /etc/hosts will now be available to paste in your browser!
File redirection also works as you would expect:
$ xsel --clipboard < /etc/hosts
$ xsel --clipboard
Just like other unix utilities, you also benefit from piping and redirection:
$ xsel --clipboard > ~/my-hosts.txt
Search for all localhost
entries within the copied content:
$ xsel --clipboard | grep -i localhost
Should note that xsel
works just as you would expect with primary
and
secondary
selections - in addition to clipboard
- though I don’t know of
many GUI applications that make use of them.