0

Let's say I have an alias on my system which I often use to tell me my system information, the alias is systeminfo, and it executes lsb_release -a which outputs:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 15.04
Release:    15.04
Codename:   vivid

Now because I use this very often, and I then copy and paste the information into my AskUbuntu questions, it would be very useful if upon execution of the command, for the output to not only be printed to the Terminal window, but also be copied to my system clipboard, so that I can save time, and not need to select the text and then copy and paste that here. So I was wondering how that could be achieved? How do I make it so that not only is it printed on screen, but also copied to the system clipboard? Preferably, I would like this question to be answered with a script which asks me if I want the information to be copied to my system clipboard in addition to being displayed on screen, but I can of course write up that script, so it would just be for convenience and to save time.

Information Update:

I have tried these, but they don't work for me:

8
  • Is this what you want askubuntu.com/questions/64333/…
    – sallp
    Aug 3, 2015 at 17:37
  • @Pilot6: Ok, I have tried that and it does not work.
    – user364819
    Aug 3, 2015 at 17:37
  • I tested it and it works. Describe what you did please.
    – Pilot6
    Aug 3, 2015 at 17:39
  • @Pilot6: I installed it, then did what they said in the answer, and nothing was copied to clipboard.
    – user364819
    Aug 3, 2015 at 17:40
  • 1
    @Pilot6: Oh that is strange, xsel suddenly started working! :D
    – user364819
    Aug 3, 2015 at 17:59

1 Answer 1

1

You can install xsel

sudo apt-get install xsel

Then run

cat /etc/lsb-release | xsel -ib

And

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.2 LTS"

will be copied to clipboard.

You can also output text from clipboard to a terminal command by e.g.

xsel -ob | cat
2
  • Just as additional info, if you need the clipboard content as input to a terminal command, you do e.g. xsel -ob | cat to pipe the clipboard content to cat and print it to standard out. Note the -o instead of -i which means "output" in contrast to "input".
    – Byte Commander
    Aug 3, 2015 at 19:18
  • I will add it. Thx.
    – Pilot6
    Aug 3, 2015 at 19:19