Skip to content

Instantly share code, notes, and snippets.

@darren
Created February 21, 2023 03:41
Show Gist options
  • Save darren/2f8e7c5a18ac8cee03f7da9a9757b7d5 to your computer and use it in GitHub Desktop.
Save darren/2f8e7c5a18ac8cee03f7da9a9757b7d5 to your computer and use it in GitHub Desktop.

清理时间机器备份遗留的快照命令行工具

把这两个函数定义放入~/.profile

function tmc() {
	for d in $(mount  |grep Time|awk '{print $3}'); do
		diskutil umount "$d HD";
	done
	
    before=$(df -hl /System/Volumes/Data |awk '{print $3}' |tail -n1)
    count=0
	for snapshot in $(tmutil  listlocalsnapshots /|awk -F. '{print $4}');do
        let 'count++'
		echo "delete snapshot $snapshot"
		tmutil deletelocalsnapshots $snapshot;
	done
    after=$(df -hl /System/Volumes/Data |awk '{print $3}' |tail -n1)
    if [[ $count -ne 0 ]]; then
        echo "Total $count snapshot(s) deleted, Size change: $before ===> $after"
    else
        echo "No snapshot deleted"
    fi
}

function tml() {
    tmutil  listlocalsnapshots /|awk -F. '{print $4}'
}
然后执行 . ~/.profile

之后就可以用命令tml列出所有的快照列表,用tmc清空所有的备份快照

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