On my local machine I have some directories (with subdirectories) with many files (jpeg and nef), like:


what I want to do is to sync on an HD all files (both jpeg and nef) but after syncing, deleting on my local computer only the nef files and keep the jpg.

Is there a way to combine this with --remove-source-files?

2 Answers 2


For safety, I would delete the .nef files in a separate step after using rsync to transfer both types of files. For example, like this:

rsync --verbose --archive --prune-empty-dirs \
    --include='*.nef' \
    --include='*.jpg' \
    --include='*/' \
    --exclude='*' \
    "$source/" "$target"

find "$source" -type f -name '*.nef' -delete

The rsync command here would only copy the .nef and .jpg files (it would skip any other file, and it would not create empty directories at $target due to --prune-empty-dirs), and then the find command would delete all .nef files.

I tend to never use --remove-source-files with rsync.

  • why --include='*/' \ and --exclude='*' \ ? BTW it seems a good solution.
    – matteo
    Commented Mar 2, 2020 at 14:35
  • @matteo I only want to copy the files with the given filename suffixes, which is why I use --exclude='*' to exclude all other files (note that I know nothing about what else you have in your source directory). To be able to recurse, I still have to include directories (these would be excluded by --exclude='*'), which is why I also have --include='*/'.
    – Kusalananda
    Commented Mar 2, 2020 at 14:47

We may need to sync twice since we dont have option to exclude source-delete.

Try as,

rsync -av --remove-source-files --exclude='*.jpg' Source/ Destination ; rsync -av Source/*.jpg Destination 

You must log in to answer this question.

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