2
rsync -avzm -e ssh /path/to/src/folder/ /path/to/dest/folder 
 --include=*/ --include=*/config.xml --exclude=*

I need to copy files(say config.xml) that are in the 2nd level directories using rsync. I am currently using the above script and its copying config.xml's from all directory levels.

What changes should I make in the above command?

1 Answer 1

2

Try this:

rsync -avzm -e ssh -f'- /*/*/' -f'+ config.xml' \
    /path/to/src/folder/ /path/to/dest/folder

Explanation

  • -f causes rsync to enable filter rule.
  • - /*/*/:
    • - meaning exclude rule.
    • /*/*/ exlucde any subdirectory from 3rd level.
  • + config.xml: + meaning include rule, cause rsync copy all files that have config.xml in filename.

Example

$ ls -R dir1/
dir1/:
dir2  dir22

dir1/dir2:
config.xml.2  dir3

dir1/dir2/dir3:
config.xml

dir1/dir22:
config.xml.22  dir33

dir1/dir22/dir33:
config.xml

$ rsync -r -f'- /*/*/' -f'+ config.xml' dir1/ /tmp

$ ls -R /tmp/dir2*
/tmp/dir2:
config.xml.2

/tmp/dir22:
config.xml.22
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .