Insert commandline output and files into the clipboard

Wouldn't it be useful to quickly pump an entire configuration file, or the output of a terminal command, into the clipboard for pasting into a website forum's posting page, or similar? Well, that's just what xclip is designed to do. It can be installed via Synaptic.

Once installed, you can either redirect text files into xclip, so that they become the clipboard contents:

...which will add the contents of the /etc/fstab configuration file to the clipboard, or you can pipe the output of a command into it: $ dmesg|xclip

...which will place the output of the dmesg command in the clipboard (dmesg shows system log output, and can be useful when diagnosing problems).

There is one proviso. The piped output/files are placed in the selection buffer clipboard, which is distinct from the standard cut/copy and paste clipboard accessible from the Edit menu of most applications. xclip's output can be pasted by positioning the cursor in the relevant spot and clicking the middle mouse button (this means pressing the scroll wheel, if your mouse has one; if not, click both the left and right mouse buttons simultaneously).

In theory the use of the -selection command-option with xclip should allow the user to add to the primary clipboard but this doesn't appear to work, perhaps because of the way the Ubuntu desktop is configured. To be honest, I see this as less of a bug and more as a feature—xclip will leave any existing clipboard contents untouched.

If you're in the process of asking for help on a forum, as mentioned earlier, see also Tip 312, on page 364, which describes how to record your on-screen actions for posting on a forum.

Have a cow talk to you M 286

Was this article helpful?

0 0

Post a comment