Sort files and directories by size

Da lumacawiki.
Versione del 17 ago 2017 alle 00:40 di Award (discussione | contributi) (Creata pagina con "To list the files and directories (in the current directory) in the descending order of file size. $ du -sk * | sort +0nr Listing only the directories (in the current direct...")
(diff) ← Versione meno recente | Versione attuale (diff) | Versione più recente → (diff)

To list the files and directories (in the current directory) in the descending order of file size.

$ du -sk * | sort +0nr

Listing only the directories (in the current directory) in descending order of size:

$ du --max-depth=1 . | sort -nr

Since the sub-directories also contains files; lets list all the files (not directories) in the descending order of file sizes

$ find . -type f -exec du -sk {} \; | sort -nr

If you want to restrict find to the current directory only and not the sub-directories, use maxdepth=1. i.e.

$ find . -maxdepth 1 -type f -exec du -sk {} \; | sort -nr

source http://unstableme.blogspot.com/2009/01/sort-files-and-directories-by-size.html