What is the command line equivalent of copying a file to clipboard?












81















What is the command line equivalent to pressing CTRL+C over a file in the file manager so that the file (not the filename) is copied to the clipboard?



A situation where this can be useful and fast, for example, is when you want to copy to the clipboard a file from the directory you are in the terminal to quickly paste the file in the directory you are in the file manager. There are others.










share|improve this question

























  • This really doesn't look like a duplicate to me. One answer is about general copy paste generally, and this one is about copy a file specific subject

    – Ulysse BN
    Aug 25 '17 at 19:07













  • I second Ulysse

    – Yasser Hussain
    Sep 12 '17 at 7:19
















81















What is the command line equivalent to pressing CTRL+C over a file in the file manager so that the file (not the filename) is copied to the clipboard?



A situation where this can be useful and fast, for example, is when you want to copy to the clipboard a file from the directory you are in the terminal to quickly paste the file in the directory you are in the file manager. There are others.










share|improve this question

























  • This really doesn't look like a duplicate to me. One answer is about general copy paste generally, and this one is about copy a file specific subject

    – Ulysse BN
    Aug 25 '17 at 19:07













  • I second Ulysse

    – Yasser Hussain
    Sep 12 '17 at 7:19














81












81








81


24






What is the command line equivalent to pressing CTRL+C over a file in the file manager so that the file (not the filename) is copied to the clipboard?



A situation where this can be useful and fast, for example, is when you want to copy to the clipboard a file from the directory you are in the terminal to quickly paste the file in the directory you are in the file manager. There are others.










share|improve this question
















What is the command line equivalent to pressing CTRL+C over a file in the file manager so that the file (not the filename) is copied to the clipboard?



A situation where this can be useful and fast, for example, is when you want to copy to the clipboard a file from the directory you are in the terminal to quickly paste the file in the directory you are in the file manager. There are others.







command-line files clipboard






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 5 mins ago









Sergiy Kolodyazhnyy

74.4k9155325




74.4k9155325










asked Nov 1 '12 at 7:46









StrapakowskyStrapakowsky

3,839112638




3,839112638













  • This really doesn't look like a duplicate to me. One answer is about general copy paste generally, and this one is about copy a file specific subject

    – Ulysse BN
    Aug 25 '17 at 19:07













  • I second Ulysse

    – Yasser Hussain
    Sep 12 '17 at 7:19



















  • This really doesn't look like a duplicate to me. One answer is about general copy paste generally, and this one is about copy a file specific subject

    – Ulysse BN
    Aug 25 '17 at 19:07













  • I second Ulysse

    – Yasser Hussain
    Sep 12 '17 at 7:19

















This really doesn't look like a duplicate to me. One answer is about general copy paste generally, and this one is about copy a file specific subject

– Ulysse BN
Aug 25 '17 at 19:07







This really doesn't look like a duplicate to me. One answer is about general copy paste generally, and this one is about copy a file specific subject

– Ulysse BN
Aug 25 '17 at 19:07















I second Ulysse

– Yasser Hussain
Sep 12 '17 at 7:19





I second Ulysse

– Yasser Hussain
Sep 12 '17 at 7:19










2 Answers
2






active

oldest

votes


















97














When you press Ctrl-C over a file in the file manager, the file's contents IS NOT copied to the clipboard. A simple test: select a file in file manager, press Ctrl-C, open a text editor, press Ctrl-V. The result is not file's contents but its full path.



In reality the situation is a bit more complicated because you can't do the opposite - copy a list of filenames from a text editor and paste them into file manager.



To copy some data from command line to X11 clipboard you can use xclip command, which can be installed with



sudo apt-get install xclip


to copy contents of a file or output of some command to clipboard use



cat ./myfile.txt|xclip -i


the text can be then pasted somewhere using middle mouse button (this is called "primary selection buffer").



If you want to copy data to the "clipboard" selection, so it can be pasted into an application with Ctrl-V, you can do



cat ./myfile.txt|xclip -i -selection clipboard


To be able to copy files from the command line and paste them in a file manager, you need to specify a correct "target atom" so the file manager recognizes the data in the clipboard, and also provide the data in correct format - luckily, in case of copying files in a file manager it's just a list of absolute filenames, each on a new line, something which is easy to generate using find command:



find ${PWD} -name "*.pdf"| xclip -i -selection clipboard -t text/uri-list


(at least this works for me in KDE). Now you can wrap into a small script which you can call, say, cb:



#!/bin/sh
xclip -i -selection clipboard -t text/uri-list


then you put it in ~/bin, set executable bit on it and use it like this:



find ${PWD} -name "*.txt"| cb


Nice, isn't it?






share|improve this answer


























  • Nice, but only works for text and it's not the file really, just the text. Suppose you have a jpg file?

    – Strapakowsky
    Nov 1 '12 at 9:33











  • Yes, I knew this effect that if you copy a file from the file manager if you paste it in another folder you paste the file, but if you paste in a text editor you get the file path.

    – Strapakowsky
    Nov 1 '12 at 9:34











  • In case of binary files (jpg etc.) everything is much more complicated. Here I asked a question inspired by yours - unix.stackexchange.com/questions/53503/… - have a read about "target atoms" and stuff

    – Sergey
    Nov 1 '12 at 9:48






  • 1





    I heard that xclip also supports file copying with xclip-copyfile and xclip-pastefile. I haven't really used it though, but it might be a solution.

    – Gladen
    Nov 1 '12 at 9:50













  • Wow, @Gladen, I think you need to post it as a separate answer. Although it does work when using xclip-copyfile and then xclip-pastefile, but doesn't seem to work with Ubuntu file manager...

    – Sergey
    Nov 1 '12 at 9:54





















9














I heard that xclip also supports file copying with xclip-copyfile and xclip-pastefile. I haven't really used it though, but it might be a solution.






share|improve this answer
























  • That just copies the file names, not the contents of the files. Just take a look at the man page examples, i.e. $ man xclip-copyfile

    – Craig
    May 8 '17 at 15:19













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f210413%2fwhat-is-the-command-line-equivalent-of-copying-a-file-to-clipboard%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









97














When you press Ctrl-C over a file in the file manager, the file's contents IS NOT copied to the clipboard. A simple test: select a file in file manager, press Ctrl-C, open a text editor, press Ctrl-V. The result is not file's contents but its full path.



In reality the situation is a bit more complicated because you can't do the opposite - copy a list of filenames from a text editor and paste them into file manager.



To copy some data from command line to X11 clipboard you can use xclip command, which can be installed with



sudo apt-get install xclip


to copy contents of a file or output of some command to clipboard use



cat ./myfile.txt|xclip -i


the text can be then pasted somewhere using middle mouse button (this is called "primary selection buffer").



If you want to copy data to the "clipboard" selection, so it can be pasted into an application with Ctrl-V, you can do



cat ./myfile.txt|xclip -i -selection clipboard


To be able to copy files from the command line and paste them in a file manager, you need to specify a correct "target atom" so the file manager recognizes the data in the clipboard, and also provide the data in correct format - luckily, in case of copying files in a file manager it's just a list of absolute filenames, each on a new line, something which is easy to generate using find command:



find ${PWD} -name "*.pdf"| xclip -i -selection clipboard -t text/uri-list


(at least this works for me in KDE). Now you can wrap into a small script which you can call, say, cb:



#!/bin/sh
xclip -i -selection clipboard -t text/uri-list


then you put it in ~/bin, set executable bit on it and use it like this:



find ${PWD} -name "*.txt"| cb


Nice, isn't it?






share|improve this answer


























  • Nice, but only works for text and it's not the file really, just the text. Suppose you have a jpg file?

    – Strapakowsky
    Nov 1 '12 at 9:33











  • Yes, I knew this effect that if you copy a file from the file manager if you paste it in another folder you paste the file, but if you paste in a text editor you get the file path.

    – Strapakowsky
    Nov 1 '12 at 9:34











  • In case of binary files (jpg etc.) everything is much more complicated. Here I asked a question inspired by yours - unix.stackexchange.com/questions/53503/… - have a read about "target atoms" and stuff

    – Sergey
    Nov 1 '12 at 9:48






  • 1





    I heard that xclip also supports file copying with xclip-copyfile and xclip-pastefile. I haven't really used it though, but it might be a solution.

    – Gladen
    Nov 1 '12 at 9:50













  • Wow, @Gladen, I think you need to post it as a separate answer. Although it does work when using xclip-copyfile and then xclip-pastefile, but doesn't seem to work with Ubuntu file manager...

    – Sergey
    Nov 1 '12 at 9:54


















97














When you press Ctrl-C over a file in the file manager, the file's contents IS NOT copied to the clipboard. A simple test: select a file in file manager, press Ctrl-C, open a text editor, press Ctrl-V. The result is not file's contents but its full path.



In reality the situation is a bit more complicated because you can't do the opposite - copy a list of filenames from a text editor and paste them into file manager.



To copy some data from command line to X11 clipboard you can use xclip command, which can be installed with



sudo apt-get install xclip


to copy contents of a file or output of some command to clipboard use



cat ./myfile.txt|xclip -i


the text can be then pasted somewhere using middle mouse button (this is called "primary selection buffer").



If you want to copy data to the "clipboard" selection, so it can be pasted into an application with Ctrl-V, you can do



cat ./myfile.txt|xclip -i -selection clipboard


To be able to copy files from the command line and paste them in a file manager, you need to specify a correct "target atom" so the file manager recognizes the data in the clipboard, and also provide the data in correct format - luckily, in case of copying files in a file manager it's just a list of absolute filenames, each on a new line, something which is easy to generate using find command:



find ${PWD} -name "*.pdf"| xclip -i -selection clipboard -t text/uri-list


(at least this works for me in KDE). Now you can wrap into a small script which you can call, say, cb:



#!/bin/sh
xclip -i -selection clipboard -t text/uri-list


then you put it in ~/bin, set executable bit on it and use it like this:



find ${PWD} -name "*.txt"| cb


Nice, isn't it?






share|improve this answer


























  • Nice, but only works for text and it's not the file really, just the text. Suppose you have a jpg file?

    – Strapakowsky
    Nov 1 '12 at 9:33











  • Yes, I knew this effect that if you copy a file from the file manager if you paste it in another folder you paste the file, but if you paste in a text editor you get the file path.

    – Strapakowsky
    Nov 1 '12 at 9:34











  • In case of binary files (jpg etc.) everything is much more complicated. Here I asked a question inspired by yours - unix.stackexchange.com/questions/53503/… - have a read about "target atoms" and stuff

    – Sergey
    Nov 1 '12 at 9:48






  • 1





    I heard that xclip also supports file copying with xclip-copyfile and xclip-pastefile. I haven't really used it though, but it might be a solution.

    – Gladen
    Nov 1 '12 at 9:50













  • Wow, @Gladen, I think you need to post it as a separate answer. Although it does work when using xclip-copyfile and then xclip-pastefile, but doesn't seem to work with Ubuntu file manager...

    – Sergey
    Nov 1 '12 at 9:54
















97












97








97







When you press Ctrl-C over a file in the file manager, the file's contents IS NOT copied to the clipboard. A simple test: select a file in file manager, press Ctrl-C, open a text editor, press Ctrl-V. The result is not file's contents but its full path.



In reality the situation is a bit more complicated because you can't do the opposite - copy a list of filenames from a text editor and paste them into file manager.



To copy some data from command line to X11 clipboard you can use xclip command, which can be installed with



sudo apt-get install xclip


to copy contents of a file or output of some command to clipboard use



cat ./myfile.txt|xclip -i


the text can be then pasted somewhere using middle mouse button (this is called "primary selection buffer").



If you want to copy data to the "clipboard" selection, so it can be pasted into an application with Ctrl-V, you can do



cat ./myfile.txt|xclip -i -selection clipboard


To be able to copy files from the command line and paste them in a file manager, you need to specify a correct "target atom" so the file manager recognizes the data in the clipboard, and also provide the data in correct format - luckily, in case of copying files in a file manager it's just a list of absolute filenames, each on a new line, something which is easy to generate using find command:



find ${PWD} -name "*.pdf"| xclip -i -selection clipboard -t text/uri-list


(at least this works for me in KDE). Now you can wrap into a small script which you can call, say, cb:



#!/bin/sh
xclip -i -selection clipboard -t text/uri-list


then you put it in ~/bin, set executable bit on it and use it like this:



find ${PWD} -name "*.txt"| cb


Nice, isn't it?






share|improve this answer















When you press Ctrl-C over a file in the file manager, the file's contents IS NOT copied to the clipboard. A simple test: select a file in file manager, press Ctrl-C, open a text editor, press Ctrl-V. The result is not file's contents but its full path.



In reality the situation is a bit more complicated because you can't do the opposite - copy a list of filenames from a text editor and paste them into file manager.



To copy some data from command line to X11 clipboard you can use xclip command, which can be installed with



sudo apt-get install xclip


to copy contents of a file or output of some command to clipboard use



cat ./myfile.txt|xclip -i


the text can be then pasted somewhere using middle mouse button (this is called "primary selection buffer").



If you want to copy data to the "clipboard" selection, so it can be pasted into an application with Ctrl-V, you can do



cat ./myfile.txt|xclip -i -selection clipboard


To be able to copy files from the command line and paste them in a file manager, you need to specify a correct "target atom" so the file manager recognizes the data in the clipboard, and also provide the data in correct format - luckily, in case of copying files in a file manager it's just a list of absolute filenames, each on a new line, something which is easy to generate using find command:



find ${PWD} -name "*.pdf"| xclip -i -selection clipboard -t text/uri-list


(at least this works for me in KDE). Now you can wrap into a small script which you can call, say, cb:



#!/bin/sh
xclip -i -selection clipboard -t text/uri-list


then you put it in ~/bin, set executable bit on it and use it like this:



find ${PWD} -name "*.txt"| cb


Nice, isn't it?







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 1 '12 at 22:51

























answered Nov 1 '12 at 8:29









SergeySergey

36.6k98799




36.6k98799













  • Nice, but only works for text and it's not the file really, just the text. Suppose you have a jpg file?

    – Strapakowsky
    Nov 1 '12 at 9:33











  • Yes, I knew this effect that if you copy a file from the file manager if you paste it in another folder you paste the file, but if you paste in a text editor you get the file path.

    – Strapakowsky
    Nov 1 '12 at 9:34











  • In case of binary files (jpg etc.) everything is much more complicated. Here I asked a question inspired by yours - unix.stackexchange.com/questions/53503/… - have a read about "target atoms" and stuff

    – Sergey
    Nov 1 '12 at 9:48






  • 1





    I heard that xclip also supports file copying with xclip-copyfile and xclip-pastefile. I haven't really used it though, but it might be a solution.

    – Gladen
    Nov 1 '12 at 9:50













  • Wow, @Gladen, I think you need to post it as a separate answer. Although it does work when using xclip-copyfile and then xclip-pastefile, but doesn't seem to work with Ubuntu file manager...

    – Sergey
    Nov 1 '12 at 9:54





















  • Nice, but only works for text and it's not the file really, just the text. Suppose you have a jpg file?

    – Strapakowsky
    Nov 1 '12 at 9:33











  • Yes, I knew this effect that if you copy a file from the file manager if you paste it in another folder you paste the file, but if you paste in a text editor you get the file path.

    – Strapakowsky
    Nov 1 '12 at 9:34











  • In case of binary files (jpg etc.) everything is much more complicated. Here I asked a question inspired by yours - unix.stackexchange.com/questions/53503/… - have a read about "target atoms" and stuff

    – Sergey
    Nov 1 '12 at 9:48






  • 1





    I heard that xclip also supports file copying with xclip-copyfile and xclip-pastefile. I haven't really used it though, but it might be a solution.

    – Gladen
    Nov 1 '12 at 9:50













  • Wow, @Gladen, I think you need to post it as a separate answer. Although it does work when using xclip-copyfile and then xclip-pastefile, but doesn't seem to work with Ubuntu file manager...

    – Sergey
    Nov 1 '12 at 9:54



















Nice, but only works for text and it's not the file really, just the text. Suppose you have a jpg file?

– Strapakowsky
Nov 1 '12 at 9:33





Nice, but only works for text and it's not the file really, just the text. Suppose you have a jpg file?

– Strapakowsky
Nov 1 '12 at 9:33













Yes, I knew this effect that if you copy a file from the file manager if you paste it in another folder you paste the file, but if you paste in a text editor you get the file path.

– Strapakowsky
Nov 1 '12 at 9:34





Yes, I knew this effect that if you copy a file from the file manager if you paste it in another folder you paste the file, but if you paste in a text editor you get the file path.

– Strapakowsky
Nov 1 '12 at 9:34













In case of binary files (jpg etc.) everything is much more complicated. Here I asked a question inspired by yours - unix.stackexchange.com/questions/53503/… - have a read about "target atoms" and stuff

– Sergey
Nov 1 '12 at 9:48





In case of binary files (jpg etc.) everything is much more complicated. Here I asked a question inspired by yours - unix.stackexchange.com/questions/53503/… - have a read about "target atoms" and stuff

– Sergey
Nov 1 '12 at 9:48




1




1





I heard that xclip also supports file copying with xclip-copyfile and xclip-pastefile. I haven't really used it though, but it might be a solution.

– Gladen
Nov 1 '12 at 9:50







I heard that xclip also supports file copying with xclip-copyfile and xclip-pastefile. I haven't really used it though, but it might be a solution.

– Gladen
Nov 1 '12 at 9:50















Wow, @Gladen, I think you need to post it as a separate answer. Although it does work when using xclip-copyfile and then xclip-pastefile, but doesn't seem to work with Ubuntu file manager...

– Sergey
Nov 1 '12 at 9:54







Wow, @Gladen, I think you need to post it as a separate answer. Although it does work when using xclip-copyfile and then xclip-pastefile, but doesn't seem to work with Ubuntu file manager...

– Sergey
Nov 1 '12 at 9:54















9














I heard that xclip also supports file copying with xclip-copyfile and xclip-pastefile. I haven't really used it though, but it might be a solution.






share|improve this answer
























  • That just copies the file names, not the contents of the files. Just take a look at the man page examples, i.e. $ man xclip-copyfile

    – Craig
    May 8 '17 at 15:19


















9














I heard that xclip also supports file copying with xclip-copyfile and xclip-pastefile. I haven't really used it though, but it might be a solution.






share|improve this answer
























  • That just copies the file names, not the contents of the files. Just take a look at the man page examples, i.e. $ man xclip-copyfile

    – Craig
    May 8 '17 at 15:19
















9












9








9







I heard that xclip also supports file copying with xclip-copyfile and xclip-pastefile. I haven't really used it though, but it might be a solution.






share|improve this answer













I heard that xclip also supports file copying with xclip-copyfile and xclip-pastefile. I haven't really used it though, but it might be a solution.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 1 '12 at 10:03









GladenGladen

1,94331337




1,94331337













  • That just copies the file names, not the contents of the files. Just take a look at the man page examples, i.e. $ man xclip-copyfile

    – Craig
    May 8 '17 at 15:19





















  • That just copies the file names, not the contents of the files. Just take a look at the man page examples, i.e. $ man xclip-copyfile

    – Craig
    May 8 '17 at 15:19



















That just copies the file names, not the contents of the files. Just take a look at the man page examples, i.e. $ man xclip-copyfile

– Craig
May 8 '17 at 15:19







That just copies the file names, not the contents of the files. Just take a look at the man page examples, i.e. $ man xclip-copyfile

– Craig
May 8 '17 at 15:19




















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f210413%2fwhat-is-the-command-line-equivalent-of-copying-a-file-to-clipboard%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

GameSpot

connect to host localhost port 22: Connection refused

Getting a Wifi WPA2 wifi connection