Linux equivalent of clip.exe

6

5

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.

ctype.h

Posted 2012-01-12T04:54:10.567

Reputation: 827

Answers

9

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).

user1686

Posted 2012-01-12T04:54:10.567

Reputation: 283 655

In response to your comment about differences between xclip and xsel, xclip seems better at handling large amounts of text than xsel, in my experience, but Tkinter's built-in copy seems to handle large amounts of text better than either. I'm not sure why. (Although Tkinter's built-in copy won't handle all Unicode characters like xclip will.) – Brōtsyorfuzthrāx – 2017-08-05T08:57:58.107