I have two directories in a bash script held by these two variables



How would I do a rsync

  1. copying files from $SRC/ to $DEST/,
  2. Verifying that the $DEST/* files match the $SRC/ files (best match available , however slow)
  3. and then delete the $SRC/ file?

Everything I google gives an example of doing an rsync and then deleting the DEST file.

I do not understand this, why would do an rsync to a destination directory, and then delete it?

do a google search and see what I mean.

  • I think you misunderstood the documentation of rsync.
    – harrymc
    Commented Jan 22, 2021 at 20:53

2 Answers 2


So the option to Move a file is --remove-source-files. Here is the man page, and see some discussion here: https://unix.stackexchange.com/questions/43957/using-rsync-to-move-not-copy-files-between-directories

Note that rsync always verifies files using checksums, but its up to you if that is sufficient to your concerns. Its notable that the checksum from the destination is calculated on transfer, not after write to disk, so its not calculated based on the resulting file and you won't get a failure, unless there is an error from the OS when it is written. Some discussion of that here: https://unix.stackexchange.com/questions/30970/does-rsync-verify-files-copied-between-two-local-drives

If this is not sufficient for your needs, consider writing a script to rsync the files without deleting the source, running rsync again with -c to select/copy files that don't match by checksum, and then finally deleting the source files with rm or whatever.


This should be a straightforward use of rsync's --remove-source-files option

rsync --dry-run --stats -av --remove-source-files "$SRC/" "$DEST/"

Remove --dry-run (and maybe --stats) when you're happy the command is going to do what you think it should do.

You must log in to answer this question.

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