How can I load a file's contents into the clipboard?
I have a files where I need to copy their contents to another file or into an application and rather than open it up, select all the text then copy and paste I'd like to know if I can effectively cat
the file contents into the clipboard. Is this possible?
A Windows program would be fine but something that works on Linux would be useful too. I don't use a Mac but it might be useful to others. Bonus points if this can be done on the command line.
Solution 1:
Since you didn't ask about Macs: cat file | pbcopy
(and likewise pbpaste
) for those.
Solution 2:
xclip (probably available in your Linux system's repos) will work for any X11 system, including most Linux versions, or even X being run under windows or Mac OSX.
Example usage: xclip -sel clip < ~/.ssh/id_rsa.pub
Solution 3:
In Linux, you can use xsel
to mimic pbcopy
and pbpaste
:
alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'
Source: Where's Walden? » pbcopy and pbpaste for Linux