Skip to content

Instantly share code, notes, and snippets.

@jeantimex
Created June 28, 2020 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeantimex/d4262a12f4527784675b85b62d9ddbe9 to your computer and use it in GitHub Desktop.
Save jeantimex/d4262a12f4527784675b85b62d9ddbe9 to your computer and use it in GitHub Desktop.

From https://www.silentorbit.com/notes/2013/rsync-by-extension/

Having a file structure full of various file types you want to sync only files of one type into a new location.

rsync -rv --include '*/' --include '*.js' --exclude '*' --prune-empty-dirs Source/ Target/

This will generate the same structure found in Source into Target but only including the JavaScript(.js) files.

Note the usage of ' around the arguments containing * since we don’t want it to be expanded in a bash shell.

The first --include '*/' is to make sure sub-directories are scanned. This would also include all directories does not include the file you want resulting in empty directories in Target. To remove these empty directories we use --prune-empty-dirs

The --include '*.js' is rather self explanatory, and you can add more as you need.

Finally we exclude all other files we don’t want using --exclude '*'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment