-   Linux - Newbie (
-   -   Copy to 'clipboard' from shell (

anth0ny5 04-05-2010 11:58 AM

Copy to 'clipboard' from shell
Seems a utility called "xclip" and "xsel" are required, but is there anything simpler, that doesn't require extra utilities, along the lines of

cat foo.txt > clipboard
This would for GNOME.

tredegar 04-05-2010 12:25 PM

Take a look at gpm which allows you to copy and paste with your mouse whilst you are in a true terminal shell ( the "boring", non-GUI type ).

anth0ny5 04-05-2010 01:24 PM


Gpm provides mouse support to text-based Linux applications like the Emacs editor and the Midnight Commander file management system. Gpm also provides console cut-and-paste operations using the mouse and includes a program to allow pop-up menus to appear at the click of a mouse button.
I'm okay with using the mouse to copy-paste from a terminal, but because the terminal might interpret characters differently I wanted to by-pass it completely, sort of like redirecting output to the clipboard. I guess there's no easy way to do this, otherwise google would have found something by now...

tredegar 04-05-2010 01:44 PM

Because you have not really explained your situation (what you'd like to be able to do, with what processes / commands ), I think I do not really understand your question.

If you are in a terminal, you can redirect "output" from one process to the "input" of another with the pipe "|" symbol. Eg
mount | grep sda

For all the gory details of redirection and piping, please see man bash

anth0ny5 04-05-2010 01:52 PM

I'm familiar with redirection, the example I give in my first post is pretty straight-forward: I'm wondering if there is some series of shell commands that will allow me to easily redirect output to the clipboard.
i.e. say I have some text "bar" in file "foo.txt". Currently inorder to get these contents into the copy buffer I need to do something like "cat foo.txt" then copy-paste the console output. This is both tedious and prone to error as I discovered with certain non-ASCII data. So what I'd like to be able to do instead is directly insert something into the copy-buffer. The only solution I've found to do this is xclip, so I'm wondering if there are any, more native, alternatives.

tredegar 04-05-2010 03:26 PM


I'm wondering if there is some series of shell commands that will allow me to easily redirect output to the clipboard.
Which "clipboard" ?

AFAIK "the shell" has no concept of "clipboard". There may be "copy buffers" in applications like vi and emacs, but I don't think this is what you are looking for. Otherwise, gpm is pretty good.

"Clipboards" are a GUI concept. How they handle them depends on the GUI you are running, but you are asking for shell commands.

anth0ny5 04-05-2010 03:37 PM

Yep, that makes sense, but like you can control the GUI via the shell (i.e. startx, system-config-display, etc.), was wondering if there was such a command to control GNOME's 'clipboard'.

Quakeboy02 04-05-2010 03:45 PM

Can you give an example of what you can't do; without posting "cat foo.txt > clipboard". What do you intend to do with what winds up in the clipboard?

The most classic example that I can come up with is how to copy text from a browser screen to a gnome terminal. In the browser, merely highlight and CTL-C, and in the terminal use "ALT-P". But, as others mentioned, this is a function of the gnome-terminal.

anth0ny5 04-08-2010 01:12 PM

To be honest, the idea came from these forums when I wanted to post the output of various logs in pastebin. Gedit garbled some of them and high-lighting from the console seemed primitive, I just thought there would be a better way, like "cat foo.log > clipboard", go to pastebin, ctrl+v.

Tinkster 04-08-2010 01:19 PM

Well ... to make a long story short: no, there's no way to
avoid those extra utilities. There's no "device node" for
the x-clipboard, or a pipe ... feel free to use the source
of xclip to make one ;}


All times are GMT -5. The time now is 01:43 AM.