On a Mac, using Bash, I tend to do
du -sh *
to tell the sizes of files and folders in the current directory, in MB and GB. But if I want to sort them by the sizes, I might do
du -sh * | sort -g
and it won't work well, because the
G is not taken into account (so 44MB might be thought to be larger than 20GB, because 44 is greater than 20).
Is there a way not to write a program and just use UNIX commands and/or a Bash function to do that?
If I care about the files and folders that are in the
GB range, I can do:
du -sh * | egrep "^\s*\d+(.\d+)?G\s" | sort -g
and it will show
2.6G ski video clips 7.6G trip 2012.mp4 12G trip photos
MB is to be considered, then the above will not work. Is there a way to do this more generally using UNIX / Mac OS X commands?