Kit Ho Kit Ho - 1 year ago 71
Linux Question

Bash: How can I list out the size of each file and directory (recursively) and sort by size decendingly?

I found that there is no easy to get way the size of a directory in Bash?

I want that when I type

ls -<some options>

it can list of all the sum of the file size of directory recursively and files at the same time and sort by size order.

Is that possible?

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download