How to list the size of each file and directory and sort by descending size in Bash?
Simply navigate to directory and run following command:
du -a --max-depth=1 | sort -n
OR add -h for human readable sizes and -r to print bigger directories/files first.
du -a -h --max-depth=1 | sort -hr
Apparently --max-depth
option is not in Mac OS X's version of the du
command. You can use the following instead.
du -h -d 1 | sort -n