Ubuntu – how can I paste copied-clipboard text to a file from terminal

12.04clipboard

I have copied something from Internet and I want that copied text to get copied to a file. But how can I copy that text without using mouse or any command like Ctrl+V. I want to do this from terminal. How can I do that in Ubuntu 12.04?

Best Answer

Using xclip.
For writing clipboard to file, overriding existing content:

xclip -o > /path/to/file.txt

or for appending clipboard to file:

xclip -o >> /path/to/file.txt