Use rsync in Linux to sync files in folders to one folder

 rsync can't do this alone, so we need a little help from "find".

find <source> -name \<search for> | rsync -av --files-from - --no-relative . <destination>

Example command:
find /var/tmp/phpB/ -name \*.css | rsync -av --files-from - --no-relative . var/tmp/phpC/

Everything from the phpB-folder, including subfolders that match the file ending .css will now sync to the phpC-folder.

Example structure:
phpB/1.css
phpB/folder1/2.css
phpB/folder2/3.css

will be synced to:
phpC/1.css
phpC/2.css
phpC/3.css

Kommentarer