How do I scp a filename with spaces?
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:
Related videos on Youtube
Alcuin Arundel
Updated on September 18, 2022Comments
-
Alcuin Arundel over 1 year
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 calledphotos 4
(with a space betweenphotos
and4
). 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]/Pictures
However, 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 asphotos 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]/Pictures
and it worked, so that escape sequence seems to be the culprit. I just can't figure out what's wrong with it.)
-
Admin almost 8 yearsMain lesson here: quit using spaces in file names. Even Apple corporation agrees on this now: support.apple.com/en-us/HT202808
-
Admin almost 8 yearsThat's fine, unless you're scp'ing files that you didn't name.
-
-
Pathros over 2 yearsHow about
scp
multiple files with the same extension? I have tried"{file1,file2}".pdf
and{"file1,file2"}.pdf
but it doesn't work:No such file or directory
. However, your first option for one file does work. But, for more than one file, how do you do that? Please help! -
Pathros over 2 yearsHow about
scp
multiple files with the same extension? I have tried"{file1,file2}".pdf
and{"file1,file2"}.pdf
but it doesn't work:No such file or directory
. However, your first option for one file does work. But, for more than one file, how do you do that? Please help! -
andrew.46 over 2 years@Pathros This looks like it could be a new question? I suspect what is happening is that the quoting has prevented the bash filename expansion you are after...
-
CPH about 2 years@Pathros Not tested, but to do multiple files I would assume you can do {"file1","file2"}