Move and copy files with rsync

I prefer the rsync over mv because of the --progress flag.

rsync -ah --progress --remove-source-files /source/path /destination/
  • If you use /source/path/, rsync will copy the contents of the source/path directory into the destination/path. It won’t create the source directory itself at the destination.
  • If you use /source/path (without the trailing slash), rsync will copy the entire source/path directory and its contents into the destination directory.

Explanation of what it does

  1. rsync: This is the command itself, used for copying and synchronizing files and directories.
  2. -ah: These are options passed to the rsync command:
    • -a: This option stands for “archive” and is used to preserve the attributes of the files and directories being copied. It includes permissions, ownership, timestamps, and more.
    • -h: This option stands for “human-readable” and is used to display file sizes in a human-readable format, such as “K” for kilobytes, “M” for megabytes, etc. This makes the output more user-friendly.
  3. --progress: This option tells rsync to display a progress bar during the file transfer. It shows the progress of each individual file being copied.
  4. --remove-source-files: This option tells rsync to remove the source files after they have been successfully transferred to the destination. In other words, it moves the files rather than just copying them.
  5. /source/path: This is the source directory or path from which you want to copy or move files. Replace this with the actual path to the source directory.
  6. /destination/: This is the destination directory where the files will be copied or moved to. Replace this with the actual path to the destination directory.

In summary, the rsync command you provided with the given options and paths is used to:

  • Copy files and directories from the source directory to the destination directory.
  • Preserve file attributes like permissions and ownership.
  • Display a progress bar during the copy operation.
  • Remove the source files after copying, effectively moving them from the source to the destination.

This command is useful for efficient file transfers and can be particularly handy when you want to both copy and remove files in a single command.