Skip to content

Instantly share code, notes, and snippets.

@darren
Created February 21, 2023 03:41
Show Gist options
  • Select an option

  • Save darren/2f8e7c5a18ac8cee03f7da9a9757b7d5 to your computer and use it in GitHub Desktop.

Select an option

Save darren/2f8e7c5a18ac8cee03f7da9a9757b7d5 to your computer and use it in GitHub Desktop.

Revisions

  1. darren revised this gist Feb 21, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion TM-CLEAN.md
    Original file line number Diff line number Diff line change
    @@ -32,4 +32,4 @@ function tml() {
    然后执行 . ~/.profile
    ```

    之后就可以用命令tml列出所有的快照列表,用tmc清空所有的备份快照
    之后就可以用命令`tml`列出所有的快照列表,用`tmc`清空所有的备份快照
  2. darren created this gist Feb 21, 2023.
    35 changes: 35 additions & 0 deletions TM-CLEAN.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    ## 清理时间机器备份遗留的快照命令行工具

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

    ```bash
    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}'
    }
    ```

    ```bash
    然后执行 . ~/.profile
    ```

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