Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to figure out how to copy the contents of a file to and from the clipboard in Linux (Ubuntu Server 11.10, bash). Is there a linux equvalent of the Windows command clip < filename? If so, what is it? In addition, the server does not have a GUI.

I have heard of such packages as xsel and xclip, but I was hoping to find something that does not require additional packages to be installed. If this is not possible, what are the advantages and disadvantages of each of the above packages? Are there other packages with the same purpose? If so, what are their advantages and disadvantages?

Thank you in advance.

share|improve this question

1 Answer 1

up vote 10 down vote accepted

Practically everything in Linux comes in the form of "additional packages" – usually shared libraries which are written once and used in hundreds of programs to avoid needless duplication. You shouldn't be afraid of them unless you are critically low on disk space.

However, Linux itself does not have a "clipboard"; this function is part of the X11 graphical interface. Both xsel and xclip require X11 to work – it does not have to be on the server (which only needs libX11 and xauth, nothing more); if you are connecting over SSH, X11 can be running on your desktop; but you still need the X11 display somewhere.

local$ ls | xsel -i
local$ ssh -Y myserver
myserver$ xsel -o > list.txt

(In this example, ssh -Y enables X11-over-SSH, allowing you to run X11 programs on the server and have them connect to the local X11 display. The differences between xsel and xclip are very minimal, their core functionality is same.)

If you are working at the console, in a text-only tty, these tools won't work. You will have to use something like gpm or screen or tmux instead – gpm works by adding mouse support to the tty's, while screen and tmux both are "terminal multiplexers" which only have the clipboard as a secondary feature (but are nevertheless useful, allowing tiling of multiple terminals in one tty).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.