How to escape & in scp How to escape & in scp shell shell

How to escape & in scp


Escaping both the spaces and the ampersand did the trick for me :

scp source_file "user@host:/dir\ with\ spaces\ \&\ ampersand"

The quotes are still needed for some reason.


When using scp or cp, special characters can break the file path. You get around this by escaping the special character.

Using cp you can use the normal method of escaping special characters, which is preceding it with a backslash. For example, a path with a space could be copied using:

cp photo.jpg My\ Pictures/photo.jpg

The remote path in scp doesn’t work escaping using this method. You need to escape the special characters using a double backslash. Using the same example, the My Photos folder would have its space escaped using:

scp photo.jpg "user@remotehost:/home/user/My\\ Photos/photo.jpg"

The double quotes are also important, the whole path with the special characters must be enclosed with double quotes.

Source : https://dominichosler.wordpress.com/2011/08/27/using-scp-with-special-characters/


If you need to escape % use %%