Skip to content

Instantly share code, notes, and snippets.

@dhirajforyou
Last active November 9, 2021 05:56
Show Gist options
  • Save dhirajforyou/727cf4e0ff513011b59470d88f7f5d4d to your computer and use it in GitHub Desktop.
Save dhirajforyou/727cf4e0ff513011b59470d88f7f5d4d to your computer and use it in GitHub Desktop.
Deleting an directory can be faster with rsync instead of rm or find -delete.
#!/bin/sh
readonly empty_dir=$(mktemp -d)
readonly target_dir="$1"
rm -rf $empty_dir
mkdir $empty_dir
rsync --recursive --delete $empty_dir/ "$target_dir"/
# --delete: delete extraneous files from dest dirs (differential clean-up during sync)
rmdir $empty_dir "$target_dir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment