Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to copy files using secure copy(scp). I am trying to execute the following command but I get error due to the space in the absolute path of the location of the directory.

scp -r -P 8484 root@ Volume/lj /home/pratheep

I am getting the following error:

scp: /media/New: No such file or directory  
scp: Volume/lj: No such file or directory

I tried using the same command putting extra back slash like

scp -r -P 8484 root@\ Volume/lj /home/pratheep

but I am still getting the same error.

Can somebody tell me how to correct it?

share|improve this question
up vote 13 down vote accepted

You should quote your file name two times, one for the local shell and one for the remote one. In the simplest case you can do one of the following

scp -r -P 8484 root@"'/media/New Volume/lj'" /home/pratheep
scp -r -P 8484 root@'"/media/New Volume/lj"' /home/pratheep

or using the help of tab completion

scp -r -P 8484 root@\\\ Volume/lj /home/pratheep
share|improve this answer
It is helpful to note that scp uses ssh as its transport which explains why there are two passes of shell interpretation happening. – msw Feb 6 '12 at 14:47

scp and rsync pass remote file names to the remote shell. This allows you to pass patterns, as in

scp remotehost:'*.txt' .

but it has the nasty consequence that you need extra quoting when supplying a remote file name.

You can pass the -s option to rsync to make it protect the file names from expansion by the remote shell. But that turns on rsync's built-in wildcard expansion, so you still need to quote \[?*.

A workaround is to transfer an archive:

ssh -P 8484 root@ 'cd "/media/New Volume" && tar cf - lj' |
tar xf - -C /home/pratheep

Another method is to mount the remote filesystem, and then use ordinary tools to perform the copy.

mkdir mnt
sshfs -p 8484 root@ mnt
cp -Rp 'mnt/media/New Volume/lj' /home/pratheep
fusermount -u mnt
rmdir mnt
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.