Using Rsync include and exclude options to include directory and file by pattern Using Rsync include and exclude options to include directory and file by pattern linux linux

Using Rsync include and exclude options to include directory and file by pattern


The problem is that --exclude="*" says to exclude (for example) the 1260000000/ directory, so rsync never examines the contents of that directory, so never notices that the directory contains files that would have been matched by your --include.

I think the closest thing to what you want is this:

rsync -nrv --include="*/" --include="file_11*.jpg" --exclude="*" /Storage/uploads/ /website/uploads/

(which will include all directories, and all files matching file_11*.jpg, but no other files), or maybe this:

rsync -nrv --include="/[0-9][0-9][0-9]0000000/" --include="file_11*.jpg" --exclude="*" /Storage/uploads/ /website/uploads/

(same concept, but much pickier about the directories it will include).


rsync include exclude pattern examples:

"*"         means everything"dir1"      transfers empty directory [dir1]"dir*"      transfers empty directories like: "dir1", "dir2", "dir3", etc..."file*"     transfers files whose names start with [file]"dir**"     transfers every path that starts with [dir] like "dir1/file.txt", "dir2/bar/ffaa.html", etc..."dir***"    same as above"dir1/*"    does nothing"dir1/**"   does nothing"dir1/***"  transfers [dir1] directory and all its contents like "dir1/file.txt", "dir1/fooo.sh", "dir1/fold/baar.py", etc...

And final note is that simply dont rely on asterisks that are used in the beginning for evaluating paths; like "**dir" (its ok to use them for single folders or files but not paths) and note that more than two asterisks dont work for file names.


Add -m to the recommended answer above to prune empty directories.