Sort output of tmutil compare by file size
I don't know exactly how sort -h
is supposed to work since it mixes the B
, K
, M
and G
prefixes, but it was at least workable for me in Mojave:
cat tmutil-compare | grep "M " | cut -c 3- | sort -h
To slightly improve upon Andreas' answer, you can sort without having to cut out the beginning part that indicates if it's an addition, removal, or change:
tmutil compare backup-1 backup-2 | grep "^[\!+-]" | sort -h -k 2
(The grep part filters out the summary lines)
The names "backup-1/2" are the full paths to two timestamped backup directories, eg /Volumes/Backup/Backups.backupdb/Computer-Name/2020-09-10-123220
. You can also pass in sub-folders if you just want to compare those, though I think they need to both point to the same path within their respective backups.
Or if you want to filter by just additions (+
) and modifications (!
) without removals (-
), for example:
tmutil compare backup-1 backup-2 | grep "^[\!+]" | sort -h -k 2
Note that the "!" needs to be escapes as it's got special meaning in bash.