, , , ,

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.