How do I scp a filename with spaces?
I'm having a little difficulty using scp to transfer files from a remote computer. The issue apparently has to do with the name of the directory the files are contained in. They're on a CD drive called photos 4 (with a space between photos and 4). When I attempted the transfer, I used the following command:
scp [remote username]@192.168.1.X:/media/[remote username]/photos\ 4/file.jpg /home/[username]/PicturesHowever, I get an error message in return saying No directory: /media/[remote username]/photos. I thought the backslash would escape the space so that the directory would be read as photos 4.
Can someone fill me in on what I'm doing wrong here?
(As an aside, I made a copy of file.jpg to the remote computer's desktop and then ran the command:
scp [remote username]@192.168.1.X:/home/[remote username]/Desktop/file.jpg /home/[username]/Picturesand it worked, so that escape sequence seems to be the culprit. I just can't figure out what's wrong with it.)
22 Answers
Spaces in directories or filenames are the natural enemy of a Linux system but can of course be escaped with due diligence. There are 3 possibilities that you could try:
scp [remote username]@192.168.1.X:"'/media/remote_username/photos 4/file.jpg'" .scp [remote username]@192.168.1.X:"/media/remote_username/photos\ 4/file.jpg" .scp [remote username]@192.168.1.X:/media/remote_username/photos\\\ 4/file.jpg .
All should work but some are syntactically easier to understand than others...
References:
3Here is the fix for ZSH users,
- scp 'username@192.168.1.X:/media/"photos 4"/file.jpg' /home/username/Pictures
- scp 'username@192.168.1.X:/media/"photos 4"/"file with space.jpg"' /home/username/Pictures
More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"