Skip to content

Instantly share code, notes, and snippets.

@nberlette
Created April 24, 2021 03:35
Show Gist options
  • Save nberlette/15224b333e7e92e0074b4bb285bc5c29 to your computer and use it in GitHub Desktop.
Save nberlette/15224b333e7e92e0074b4bb285bc5c29 to your computer and use it in GitHub Desktop.
## Purge macOS Time Machine's Local Snapshots
## By Nicholas Berlette <github.com/nberlette>
## Usage:
## purge_local_snapshots [-q|--quiet]
function purge_local_snapshots() {
quiet=$(echo ${1,,} | grep "\-q")
snapshots=$(tmutil listlocalsnapshotdates | grep "-")
if [[ "${#snapshots}" -eq "0" ]]; then
[[ "${#quiet}" -eq "0" ]] && echo "No snapshots available!"; return;
else
i=1
ns1=$(date +"%N")
for d in $snapshots; do
ns2=$(date +"%N")
sudo tmutil deletelocalsnapshots $d && { [[ "${#quiet}" = "0" ]] && echo "#$i. $d ($(($ns2-$ns1)) nsec)"; }
i=$(($i+1))
done
fi
}
## pass $* so this can be run as a file
purge_local_snapshots "$*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment