2

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?

yogsma
  • 245
  • 1
  • 3
  • 12

2 Answers2

2

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.

Istvan
  • 2,582
  • 3
  • 22
  • 29
2

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.

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151