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
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.
- 451
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.
- 28,986
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.
- 103
- 1,175
- 3
- 11
- 23