Server Fault is a question and answer site for system and network administrators. 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 have a folderA remotely which has 2 subfolders folderB and folderC.I have to search for my

file where it is located in the 2 subfolders(folderB and folderC) and should copy it.

Is it possible with rsync and a script like thing.

share|improve this question

You could always use find over ssh:

scp user@hostname:`ssh user@hostname "find folderA -name \"targetFile\" "` .

This opens up two SSH connections, so you'll be prompted for the password twice unless you've set up unprotected key-files.

share|improve this answer
It doesn't work if file name including spaces. – quanta Sep 28 '11 at 16:34
It will if you escape your spaces with a '\' character – spikeheap Sep 29 '11 at 8:20
It is not a concrete filename. How do you escape it from your above command? – quanta Sep 29 '11 at 8:23

Sure, using rsync just exclude everything, then only include the name of the file you want:

$ rsync --exclude="*" --include="filename" -e ssh user@remote:path/to/folderA/ .
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.