Skip to content

Instantly share code, notes, and snippets.



Last active May 30, 2021
What would you like to do?
Script to automatically remote old Mac OSX Time Machine Backups older than a specified number of days


  • gfind (via brew install findutils)
  • Time Machine drive mounted on your computer (or you can change path from standard /Volume/Time\ Machine\ Backups/Backups.backup.db/
  • Admin/sudo access in the OSX terminal


  • Be sure to set the correct machine name. You can check the actual folder things are going into by looking in the backup location.
  • By default, it erases all backups older than 30 days. Adjust as desired.


$ sudo ./
*-* Removing old Time Machine Backups for vitruvius older than 30 days *-*
Deleting: /Volumes/Time Machine Backups/Backups.backupdb/vitruvius/2014-07-21-231955
Deleted (29.7G): /Volumes/Time Machine Backups/Backups.backupdb/vitruvius/2014-07-21-231955
Total deleted: 29.7G
Elapsed time: 2768 secs.
# Pre-requesite is that GNU linux findutils package is installed (brew install findutils) for gfind
# Should be possible to just use find but I have not tested it (should just omit -daystart)
BACKUP_LOCATION=/Volumes/Time\ Machine\ Backups/Backups.backupdb/
if [ ! -d "${BACKUP_LOCATION}" ]; then
echo "${BACKUP_LOCATION} is currently not accessible. Please connect your Time Machine disk or change the path."
echo "*-* Removing old Time Machine Backups for ${MACHINE_NAME} older than ${DAY_AGE} days *-*"
# Get a list of all the
result=$(gfind "${BACKUP_LOCATION}""${MACHINE_NAME}"/ -daystart -maxdepth 1 -mindepth 1 -mmin +$((60*24*${DAY_AGE})))
echo "$result"
if [ -n "$result" ]; then
while read -r line; do
START_TIME=$(date +%s)
tmutil delete "$line"
END_TIME=$(date +%s)
echo "Elapsed time: $(($END_TIME - $START_TIME)) secs."
done <<< "$result"
echo "Finished!"
echo "Did not find any Time Machine Backups older than ${DAY_AGE} days old."

This comment has been minimized.

Copy link

@septs septs commented Feb 17, 2021

$ tmutil machinedirectory
/Volumes/Time Machine Backups/Backups.backupdb/CBDesktop02

use tmutil machinedirectory command can simplify logic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment