Created
January 22, 2020 20:27
-
-
Save briankendall/236607f60e428457655290c6d8f55ae1 to your computer and use it in GitHub Desktop.
Python 2 script for deleting all local snapshots on a mac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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