M BUZZ CRAZE NEWS
// general

How to pipe/dump clipboard contents to a file?

By David Jones

I want to pipe/dump the contents (esp. text) of the clipboard/Ctrl+C to a file, preferably using Bash or Perl (in order). I'd rather not use GUI applications please.

4 Answers

How to pipe clipboard contents to a file?

You can do it using xsel. Type in terminal to install it,

sudo apt-get install xsel

To put the contents of a file to the clipboard use:xsel -b < some.txt

To paste the contents of the clipboard to a file use.

`xsel -b >> some.txt`

Copy file content/string to clipboard

You can go through this answer by Radu Rădeanu which described how you can copy file content/string from a terminal to clipboard that can be pasted using Ctrl+V

8

You can also use xclip (install with sudo apt-get install xclip) like so:

xclip -selection clipboard -o > clipboard.txt

which will put the clipboard into clipboard.txt in the working folder.

4

Here's a way that is done from the command line and does not require any libraries:

  1. Copy your data to the clipboard.

  2. Run cat > /your/file/path in the terminal window

  3. Paste the contents to the terminal window

  4. Press press Ctrl + D.

Tested on ubuntu.

7

An other option is gpaste which has the advantage of being able to get several previous clipboard copies.

Install it by

sudo apt-get install gpaste

And you can recover the last copy with

gpaste-client get 0 > file.txt

Note that you can change the 0 to any number to get the other copies.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy