How do I copy a file to the clipboard in the terminal (linux) [closed]

99封情书 提交于 2020-07-23 06:37:24

问题


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

  1. No file in clipboard
  2. 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)
  3. Now the file is in the clipboard and I can paste it anywhere
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!