Skip to content

Instantly share code, notes, and snippets.

@briankendall
Created January 22, 2020 20:27
Show Gist options
  • Save briankendall/236607f60e428457655290c6d8f55ae1 to your computer and use it in GitHub Desktop.
Save briankendall/236607f60e428457655290c6d8f55ae1 to your computer and use it in GitHub Desktop.
Python 2 script for deleting all local snapshots on a mac
#!/usr/bin/env python
from subprocess import call, check_output
import re
def main():
output = check_output(['tmutil', 'listlocalsnapshots', '/'])
lines = output.strip().split('\n')
for i, line in enumerate(lines):
match = re.search(r'com.apple.TimeMachine.(20\d\d-\d\d-\d\d-\d{6})', line)
if match is None:
print("Error: couldn't determine local snapshot timestamp for line: %s" % line)
continue
print("Deleting local snapshot %d of %d: %s" % (i+1, len(lines), match.group(1)))
call(['tmutil', 'deletelocalsnapshots', match.group(1)])
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment