Suppose I click on a file in Nautilus. How can I copy the full address to the clipboard, and then easily paste it into a shell command that I'm typing in a terminal?

  • Yes, press Ctrl+C to copy, which you already know… What's the question here? – Gilles Oct 9 '14 at 23:11
  • I'm not looking to copy the file, I'm looking to copy the address of the file. – George Oct 9 '14 at 23:35
  • And when you paste in a terminal, you get the address of the file. – Gilles Oct 9 '14 at 23:40
  • I wasn't aware of this. But trying it out, it doesn't seem to paste in a terminal ready format (i.e., if there are spaces in the file names or what not). – George Oct 9 '14 at 23:42
  • What do you mean by “terminal ready format”? Do you mean that you want the file name quoted for shell use (e.g. '/home/george/some thing.txt'), and not the file name (like /home/george/some thing.txt)? You should write what you mean in your question, we can't read your mind. – Gilles Oct 9 '14 at 23:45

Press Ctrl+C to copy. When you paste into a terminal, what you'll get is the file name (with its full path).

You get the raw file name, which won't be directly usable in a shell command if it contains spaces or other special characters. To use the file name in a command, don't use a paste command from the terminal, let the shell do the pasting. Install the program xsel (packaged in most distributions) and call it on your command line, inside a command substitution. You need double quotes around the command substitution to protect special characters such as spaces.

$ ls -l "`xsel -b`"

Click on it, press Ctrl+C and just paste it. If you use xclip -selection c w for pasting instead of Ctrl+Shift+V you won't get any file:// prefix or URL encoding.

I recommend wrapping that into something more convenient to use and using it for manipulating the clipboard when you're in the terminal. Here's an article that discusses this method using the commandline tool vipe, it's titled: VIPE WITHOUT MOREUTILS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.