Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

There's too much going on for me to get my noobie head around here. I'm wanting to download all files that end -123.jpg from a multitude of nested directories on a remote server. Some of these directories have spaces in their names. I'm thinking that the command should be along the lines of:

scp -r user@server:/path/to/parent\ directory/*/*/*123\.jpg ./

… where "parent\ directory" is a directory name with a space, and the specified path goes as deep as it can before it splits off to various sub-directories, for example dir/sub dir/[uniquely_id]-123.jpg file. (Note that these sub-directories often contain spaces too, should that affect the * wildcard)

I'm getting 'no match' returned for this, or 'no such file or directory' if I meddle with the space escaping. I'm thinking therefore that it's the recursion or the wildcard that I've got wrong.

Thanks in advance.

share|improve this question

migrated from Nov 2 '10 at 0:28

This question came from our site for professional and enthusiast programmers.

Lacking your server layout for testing I don't know if the following command actually works, but I think rsync would be better than scp in that case, as you can specify in- and exclude patterns. Something like:

rsync -arvzSH  --include "*123.jpg" --exclude "*" user@server:/path/to/parent\ directory/ /path/to/target directory/

may work. But you better double check the rsync documentation.

share|improve this answer

Filename escaping with scp is tricky; your arguments get (re)expanded on the remote side. "Interesting" characters have to be double quoted, to avoid special handing by your local shell and by the remote. I would expect both the following to work for you:

scp user@server:'/path/to/parent\ directory/*/*/*123.jpg' ./
scp user@server:'"/path/to/parent directory"/*/*/*123.jpg' ./

If that's confusing, rsync is pretty easy to use (as lothar mentions), and piping tar or cpio through ssh is pretty easy too.

ssh user@server 'cd /path/to/parent\ directory;
                 find -name "*123.jpg" -print0 | cpio -0 -o' |
    cpio -i -d -v
share|improve this answer
Thanks. The revised scp solution worked just fine. – hyppy Nov 2 '10 at 16:11

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.