rsync
rsync
see also my mess over at ssh, scp, rsync
only include specific file (pattern)
I only want to sync files which match a specific name and exclude everything else.
- Important: the include/exclude lists are case sensitive.
In this case, I want to sync all files with foo and bar in the name, so it’d match the files foobar and Superduper.jpg
rsync -avP --include={*/,*foo*,*Super*} --exclude='*' rsync://example.com/files/ ~/Downloadsor with individual include arguments:
rsync -avP --include='*.yaml' --include='*.yml' --include='.env' --exclude='.git' --exclude='*' ~/source/ ~/dest/include / exclude from file pattern
example include_patterns.txt file to specify which files should be included
+ */
+ .env
+ *.yaml
+ *.yml
+ *.txtuse it in rsync like this:
rsync -avxiP --include-from="include_patterns.txt" ~/source ~/destthis is a basic example, it’s worth checking out the filter rules of rsync’s man page
do not copy empty directories
-m or --prune-empty-dirs: Prevents rsync from creating empty directories in the destination.
rsync -avPm ~/source ~/destdelete files on the source
you might want to run this first with -n for a dry run
rsync --remove-source-files -av ~/source ~/dest