0

tmutil compare gives differences between two backups. But I wonder how do I sort the output by file size? With GNU sort, there is the --human-numeric-sort option for this, but the sort which is part of macOS doesn't support this. So how can I sort the result by file size?

3
  • Welcome to AskDifferent. You had two questions in here. This site works better when there is only one question per question. That way, it's easier for other people to find solutions if they have the same problem. I've edited out your second question, but feel free to ask it separately.
    – nohillside
    Dec 27, 2018 at 11:10
  • @nohillside I am sorry but this kind of post editing is incredibly unusual on StackExchange and quite unacceptable.
    – atapaka
    Dec 28, 2018 at 12:23
  • Look, we know from a lot of experience that questions containing more than one actual question don't work very well. People might answer one, or the other, or both. One of the questions might have already come up before, so we could close it as a duplicate. The best answers for the two questions might be in two different posts, so which one are you going to accept? Reading apple.meta.stackexchange.com/questions/882/… and apple.stackexchange.com/help/editing will provide more details on this.
    – nohillside
    Dec 28, 2018 at 12:30

3 Answers 3

1

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
1

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.

0

Please use the following command that works perfectly for me on mac. It takes the second field (size of file) and then sorts it using human readable format that honors K, M, G notation for size.

sort -k2 -h "filename"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .