Lee Lee - 4 months ago 13x
Bash Question

Update using rsync and remove from the source folder

I want to

contents from

  • The files end with extensions composed by 4 digits

  • If a file does not exist in remote path, copy the file to remote and remove from local

  • If a file exists in remote path and the size is no less than the local one, do not copy the file to remote and remove it from local

I tried

rsync -avmhP --include='*.[0-9][0-9][0-9][0-9]' --include='*/' --exclude='*' --size-only --remove-source-files /local/path server:/remote/path

However, some files existing in the remote path remain in local path.

Another question is, why we need
--include='*/' --exclude='*'
? Why
alone doesn't work for the file filtering?


Do you mean --remove-sent-file instead of remove-source-file ?

According to the rsync man page :


This tells rsync to remove from the sending side the files and/or symlinks that are newly created or whose content is updated on the receiving side. Directories and devices are not removed, nor are files/symlinks whose attributes are merely changed.

That's means that only transferred file (the ones whom size changed) are deleted from source. To active the include file, you first need to exclude all the other BUT my include pattern. The 3 arguments you used mean "I excluded all files (--include='*/' --exclude='*') but the ones matching my pattern (--include='*.[0-9]{4}')

From man page :


don’t exclude files matching PATTERN


exclude files matching PATTERN