rcp & rmv: copying & moving using rsync with the simplicity of cp & mv

These two commands rcp and rmv acts a direct replacement for cp and mv for copying or moving files using rsync.

Instead of doing:

rsync -avh –partial –info=progress2 source dest
rsync -avh –partial –info=progress2 –remove-source-files source d…


This content originally appeared on DEV Community and was authored by Yoshi Nakamoto

These two commands rcp and rmv acts a direct replacement for cp and mv for copying or moving files using rsync.

Instead of doing:

rsync -avh --partial --info=progress2 source dest
rsync -avh --partial --info=progress2 --remove-source-files source dest

Now you can simply do:

rcp source dest
rmv source dest

You can also include additional rsync options, here are two examples with -z for compression (great for faster network transfers) and --dry-run to see what gets transferred without actually transferring (yet).

rcp -z source dest
rmv --dry-run source dest

The rcp() and rmv() shell functions

You can copy and paste the following lines in your .zshrc or .bashrc file.

# On macOS, the default `rsync` tool does not support the
# `--info=progress2` command, so run `brew install rsync`
# to get the latest rsync.
alias rsync="/opt/homebrew/bin/rsync"

# Function to copy files
# Usage: rcp [rsync_options] source destination
rcp() {
  local options="-avh --partial --info=progress2"
  local source_path="$1"
  local dest_path="$2"

  if [[ -n "$2" ]]; then
    shift 2
    rsync $options "$@" "$source_path" "$dest_path"
  else
    echo "Usage: rcp [rsync_options] source destination"
    return 1
  fi
}

# Function to move files and delete empty directories
# Usage: rmv [rsync_options] source destination
rmv() {
  local options="-avh --partial --info=progress2 --remove-source-files"
  local source_path="$1"
  local dest_path="$2"

  # Shift off the first two arguments (source and destination)
  # This leaves any remaining arguments to be passed as rsync_options
  if [[ -n "$2" ]]; then
    shift 2
    rsync $options "$@" "$source_path" "$dest_path" && \
    find "$source_path" -type d -empty -delete
  else
    echo "Usage: rmv [rsync_options] source destination"
    return 1
  fi
}

macOS users: Upgrade your rsync

The default rsync tool that comes bundled with macOS is v2.6.9 does not support the --info=progress2 command, so run brew install rsync to get the latest rsync.

❯ /usr/bin/rsync --version
openrsync: protocol version 29
rsync version 2.6.9 compatible

❯ /opt/homebrew/bin/rsync --version
rsync  version 3.4.1  protocol version 32

Handling the removal of empty directories

The --remove-source-files option in rsync does not remove empty directories after all the files has been moved. Therefore, in the rmv() shell function above, you will notice that it runs an additional command to remove the empty directories using find after rsync has finished running.

So there you have it! These two little shell functions, rcp and rmv, wrapping up the power of rsync into something as easy to use as cp and mv.

No more remembering long strings of options, just a simple command that gets the job done, with a nice progress bar to boot.


This content originally appeared on DEV Community and was authored by Yoshi Nakamoto


Print Share Comment Cite Upload Translate Updates
APA

Yoshi Nakamoto | Sciencx (2025-09-09T16:14:09+00:00) rcp & rmv: copying & moving using rsync with the simplicity of cp & mv. Retrieved from https://www.scien.cx/2025/09/09/rcp-rmv-copying-moving-using-rsync-with-the-simplicity-of-cp-mv/

MLA
" » rcp & rmv: copying & moving using rsync with the simplicity of cp & mv." Yoshi Nakamoto | Sciencx - Tuesday September 9, 2025, https://www.scien.cx/2025/09/09/rcp-rmv-copying-moving-using-rsync-with-the-simplicity-of-cp-mv/
HARVARD
Yoshi Nakamoto | Sciencx Tuesday September 9, 2025 » rcp & rmv: copying & moving using rsync with the simplicity of cp & mv., viewed ,<https://www.scien.cx/2025/09/09/rcp-rmv-copying-moving-using-rsync-with-the-simplicity-of-cp-mv/>
VANCOUVER
Yoshi Nakamoto | Sciencx - » rcp & rmv: copying & moving using rsync with the simplicity of cp & mv. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/09/09/rcp-rmv-copying-moving-using-rsync-with-the-simplicity-of-cp-mv/
CHICAGO
" » rcp & rmv: copying & moving using rsync with the simplicity of cp & mv." Yoshi Nakamoto | Sciencx - Accessed . https://www.scien.cx/2025/09/09/rcp-rmv-copying-moving-using-rsync-with-the-simplicity-of-cp-mv/
IEEE
" » rcp & rmv: copying & moving using rsync with the simplicity of cp & mv." Yoshi Nakamoto | Sciencx [Online]. Available: https://www.scien.cx/2025/09/09/rcp-rmv-copying-moving-using-rsync-with-the-simplicity-of-cp-mv/. [Accessed: ]
rf:citation
» rcp & rmv: copying & moving using rsync with the simplicity of cp & mv | Yoshi Nakamoto | Sciencx | https://www.scien.cx/2025/09/09/rcp-rmv-copying-moving-using-rsync-with-the-simplicity-of-cp-mv/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.