问题
I would like to copy a file to the clipboard with the terminal, like when right clicking a file and selecting "copy" in the gui. Someting like "cp test.txt" (without a destination) so whenever I want, I could right click and paste the file (or files) in the gui. Thank you
- No file in clipboard
- What I am trying to do: (copy a file to the clipboard with the terminal). Exactly like right clicking a file and selecting copy. (test.txt already on desktop)
- Now the file is in the clipboard and I can paste it anywhere
- File is pasted
回答1:
What you want to achieve isn't impossible, but looks like there isn't any universal solution. The only thing I managed to find was this question: Copy file from commandline, paste into Gnome window or vice-versa.
When you want to copy and move files via the X clipboard in CLI use xclip-copyfile
and xclip-pastefile
.
Additionally:
cat ~/foo.c | xclip -i -selection clipboard
This will copy the contents of file ~/foo.c
into CLIPBOARD (without -selection clipboard
it will copy into PRIMARY).
Tools will be different on other systems (e.g. on Windows will be copy
) or if you aren't using X server.
来源:https://stackoverflow.com/questions/62852973/how-do-i-copy-a-file-to-the-clipboard-in-the-terminal-linux