Recently, I'd copied some text from browser and I was too lazy too go and paste it in file by using file explorer. I was wandering if I can paste it directly to the file by just using terminal and some commands. Any suggestions?
Asked
Active
Viewed 1.8k times
2 Answers
16
You can use cat, with a here document e.g.
cat > somefile
hit Enter then paste from the default buffer with a middle click or standard terminal emulator shortcut Ctrl+Shift+V, and terminate the input with Ctrl+D.
Ex.
$ cat > somefile
foo
bar
baz
^D
Use >> in place of > if you want to append to somefile instead of overwrite it.
dessert
- 40,956
steeldriver
- 142,475
8
You can use xclip (sudo apt install xclip) for that:
xclip -se c -o # print the clipboard's content to stdout
xclip -se c -o >out # print the clipboard's content to file named “out”
-se c– use theclipboardselection, leave out or change to-se pto use the default buffer instead (the default buffer holds the last thing you selected, e.g. by double-clicking a word)-o– print to stdout>out– redirect stdout to file namedoutoverwriting it, change to>>outto append to the file's content
See man xclip (How can I get help on terminal commands?) for more.
dessert
- 40,956