Skip to content

Instantly share code, notes, and snippets.

@welsonla
Last active January 1, 2020 08:48
Show Gist options
  • Select an option

  • Save welsonla/0e4c4a818abfae0400a4087b54e81c43 to your computer and use it in GitHub Desktop.

Select an option

Save welsonla/0e4c4a818abfae0400a4087b54e81c43 to your computer and use it in GitHub Desktop.

Revisions

  1. welsonla revised this gist Jan 1, 2020. No changes.
  2. welsonla created this gist Jan 1, 2020.
    26 changes: 26 additions & 0 deletions snapshots_clear.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #/bin/bash

    #diskspace info
    puts "Current Diskspace info:"
    puts "---------"
    puts %x[df -lh /]

    #list localsnapshots
    puts "\n\n---------"
    list = %x[tmutil listlocalsnapshots /]
    puts list

    #delete snapshots
    puts "\n\n---------"
    puts "Start delete snapshots:"
    matches = list.scan(/\d{4}-\d{2}-\d{2}-\d{6}/)
    matches.each_with_index{|snapshoot,index|
    puts "delete the listlocalsnapshots #{snapshoot}"
    sh = "tmutil deletelocalsnapshots #{snapshoot}"
    system(sh)
    }

    #diskspace info after delete snapshot
    puts puts "\n\n---------"
    puts "Diskspace info after delete snapshots:"
    puts %x[df -lh /]