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 need to go through subdirectories of a directory /home/userName/ and find the files whose names begin with SY101 and their extension is .csv and transfer those files to another server. My question is how do I loop through subdirectories and keep looking for the files?

share|improve this question
up vote 2 down vote accepted

You could do several things, this is probably the most efficient, but I dont know anything about the size of your files and your link between servers, but let me try:

find /home/userName/ -name 'SY101*.csv' | \
xargs tar cvfz - | ssh hostname 'tar xzf -'

This is going to copy the files to your home on the other server.

Please note the full path will be transfered.

share|improve this answer
What do you mean by full path will be transferred? – yogsma Sep 16 '10 at 21:34
I would recommend the -print0 option for find and the -0 option for xargs just in case any filenames have spaces in them. – Dennis Williamson Sep 16 '10 at 22:34

Something like this might work for you:

rsync --recursive --include='SY101*.csv' --include='*/' --exclude='*' /home/userName/ username@hostname:destdir

This will reproduce the directory hierarchy of the source on the destination.

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.