Skip to content

Instantly share code, notes, and snippets.

@iuriguilherme
Created January 5, 2021 21:06
Show Gist options
  • Save iuriguilherme/f726df0f00917c5b0715112125a0935b to your computer and use it in GitHub Desktop.
Save iuriguilherme/f726df0f00917c5b0715112125a0935b to your computer and use it in GitHub Desktop.
Move files safely across filesystems
#!/bin/bash
## This script will move safely all files and folders in the arguments list to the last argument. It uses rsync so it can be sent to remote servers.
rsync -avvhSP --remove-source-files "$@"
for DIR in "${@}"
do
## like `rmdir` but recursively for every argument (only removes empty directories)
find "${DIR}" -type d -empty -delete
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment