Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to copy the output into the clipboard without using the mouse?

For example, I would like to do something like this:

$ pwd >> clipboard

share|improve this question
cat /etc/passwd | xsel --clipboard – Abhisheietk Apr 10 '12 at 7:25
up vote 16 down vote accepted

You can get and use the xclip and xsel commands. Instructions for obtaining and using them are here.

share|improve this answer
Thanks, I never knew that. – Dan McGrath Feb 5 '10 at 2:39
xclip doesn't work here. – brauliobo Apr 25 '14 at 18:18
@brauliobo: Where's "here"? Seriously, what do you mean? It doesn't work in what way, exactly? – Dennis Williamson Apr 25 '14 at 18:26
@DennisWilliamson I've tried cat file | xclip and it doesn't work – brauliobo Apr 25 '14 at 18:44
@brauliobo: I presume klipper is a clipboard viewer. Try cat file | xclip -selection clipboard Without the extra arguments, xclip copies into the primary (middle-click-paste) clipboard instead of the Ctrl-C/Ctrl-V/right-click-context-menu clipboard. – Dennis Williamson Apr 25 '14 at 19:48

I'm afraid there is no such thing as "clipboard" in most linux shells, at least none I know of. There's a clipboard in the X server (if your system has X11, you may access it using xclip command). If you connect to your shell account using some ssh/terminal emulator software, like PuTTy, you can use the clipboard of the system you are using, but that still would be an external clipboard and you might not be able to avoid using mouse.

What I have found is this little neat bash script, found at . It basically creates a temporary file which serves as a clipboard - you can clear, execute, write etc. your temporary data using a set of commands, which is actually what a clipboard does ;)

share|improve this answer
the op was just a little bit unclear about his setup: he meant the clipboard of the xserver. – akira Feb 5 '10 at 8:44

If you are on a MAC you can use pbcopy like this:

pbcopy < thing_to_write_to_clipboard
share|improve this answer

I made a small tool providing similar functionality, without using xclip or xsel. Std out is copied to a clipboard and can be pasted again in the terminal, see:

Note, that this tool does not need an x-session. The clipboard can just be used within terminal and not be pasted by ctrl+v or middle-mouse-click into other x-windows

share|improve this answer

And an ugly way, for cases when you want to copy terminal output to clipboard but don't have a mouse connected to your machine — using "mouse keys" feature of X.

Press Shift+NumLock, and your numpad keys will work to control cursor movement. You can then press Num 0 to simulate press & hold LMB, and move the cursor as you need, then press Num 5 to simulate release of LMB. Now you've selected your text. To simulate RMB you press Num - to change active mouse button, then Num 5 to get context menu. Now you want to return to LMB mode: press Num /. Now you can move your cursor to "Copy" menu entry and press Num 5. That's all. You have your text in clipboard. Press Shift+NumLock to get your numpad to its original function.

PS: In some distros (e.g. Kubuntu) mouse keys shortcut appears to be disabled by default or somehow hidden.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .