How do I escape spaces in path for scp copy in Linux? How do I escape spaces in path for scp copy in Linux? unix unix

How do I escape spaces in path for scp copy in Linux?


Basically you need to escape it twice, because it's escaped locally and then on the remote end.

There are a couple of options you can do (in bash):

scp user@example.com:"'web/tmp/Master File 18 10 13.xls'" .scp user@example.com:"web/tmp/Master\ File\ 18\ 10\ 13.xls" .scp user@example.com:web/tmp/Master\\\ File\\\ 18\\\ 10\\\ 13.xls .


works

scp localhost:"f/a\ b\ c" .scp localhost:'f/a\ b\ c' .

does not work

scp localhost:'f/a b c' .

The reason is that the string is interpreted by the shell before the path is passed to the scp command. So when it gets to the remote the remote is looking for a string with unescaped quotes and it fails

To see this in action, start a shell with the -vx options ie bash -vx and it will display the interpolated version of the command as it runs it.


Use 3 backslashes to escape spaces in names of directories:

scp user@host:/path/to/directory\\\ with\\\ spaces/file ~/Downloads

should copy to your Downloads directory the file from the remote directory called directory with spaces.