Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cyrillbolliger/7c03da7699966ca3a55eca413936fafe to your computer and use it in GitHub Desktop.
Save cyrillbolliger/7c03da7699966ca3a55eca413936fafe to your computer and use it in GitHub Desktop.
Free purgeable disk space - Delete local snapshots on apfs

Local snapshots beef up the disk space of your mac. If the diskspace is marked purgeable but isn't freed when you empty the trash, chances are high, that local timemachine snapshots are using it.

Delete local snapshots (on volumes formated with APFS)

  1. Open the terminal
  2. List the disks and partitions number using diskutil list.
  3. Watch out for disks marked as synthesized and the partitions of type APFS Container Scheme
  4. The PARTITION_IDENTIFIER used later on, is composed of disk concatenated with the disk number, an s and the partition number. So for the following diskutil list output it would be disk4s1:
/dev/disk4 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +499.9 GB   disk4
                                 Physical Store disk3s2
   1:                APFS Volume VM                      403.2 GB   disk4s1

If you want to clean your main disk, it's most probabely disk1s1. So replace all subsequent PARTITION_IDENTIFIER with disk1s1.

  1. List the snapshots of the given partition: diskutil apfs listSnaps PARTITION_IDENTIFIER
  2. Delete those snapshots: diskutil apfs deleteSnapshot PARTITION_IDENTIFIER -name SNAPSHOT_NAME
  3. Reboot your system (or remount the disk, if you can)

Delete all snapshots at once

To delete all local snapshots of a certain partition at once run: diskutil apfs listSnaps PARTITION_IDENTIFIER | grep Name | sed -E 's/\|?[[:space:]]+Name:[[:space:]]+//' | xargs -I % diskutil apfs deleteSnapshot PARTITION_IDENTIFIER -name %

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