How to pipe/dump clipboard contents to a file?
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 xselTo 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
8You can also use xclip (install with sudo apt-get install xclip) like so:
xclip -selection clipboard -o > clipboard.txtwhich will put the clipboard into clipboard.txt in the working folder.
Here's a way that is done from the command line and does not require any libraries:
Copy your data to the clipboard.
Run
cat > /your/file/pathin the terminal windowPaste the contents to the terminal window
Press press
Ctrl + D.
Tested on ubuntu.
7An other option is gpaste which has the advantage of being able to get several previous clipboard copies.
Install it by
sudo apt-get install gpasteAnd you can recover the last copy with
gpaste-client get 0 > file.txtNote that you can change the 0 to any number to get the other copies.
More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"