13

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?

1

4 Answers 4

18

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
1
  • 1
    Good one. +1 from me. May 22, 2014 at 15:32
16

If you don't want (or you can't) install extra software, you can do it with cat

cat > /path/to/file.txt

after this the terminal waits user input, so you can paste from your clipboard:

Ctrl + Shift + v

Then press Enter

And exit cat with Ctrl + c

I learned this while watching:
https://www.youtube.com/watch?v=dDddKmdLEdg

4
  • 1
    This answer worked on mac terminal. Thank you. Jul 6, 2020 at 14:53
  • 2
    Finally, a solution that works over ssh!
    – mchid
    Nov 26, 2020 at 0:17
  • This is the WAY BETTER answer!!!
    – GWD
    Feb 19, 2021 at 18:10
  • right-click to paste, instead of Ctrl + Shift + v, worked for me (Ubuntu terminal on WSL), but otherwise great solution, installed xclip for nothing as it did not work.
    – sritmak
    Sep 15, 2022 at 12:13
0

copy to clipboard then

xsel -o >> note.txt

but it not include new line "\n"

用件、用例(scenario): I input some Japanese 言葉 on google.translate.com then I'd like to take a note to save input history for review it later.

-1

Press Ctrl + Shift + C to Copy

Press Ctrl + Shift + V to Paste

1
  • "how can I copy that text without using mouse or any command like Ctrl+V"
    – Tim
    Jun 1, 2022 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.