Print list of folders sorted by their size

In order to print a list of folders and files sorted according to their size you only need two built-in UNIX commands, put together using the pipe (“|”):

  1. du
  2. sort
du -h /var/www/ --max-depth=1 | sort -h

Whereas du gives you the storage space occupied by certain files and folders, sort actually sorts the resulting list. Using the additional parameter max-depth you can specify the folder depth which du will use to echo files and folders on the shell during its recursive parsing process.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *