• Find files and folders disk usage in Linux

If you need to find which files and folder are taking up the most space in Linux here is a handy command you can run.

du -hsx *

Output something like this:

60K     error_docs
968M    httpdocs
3.5G    httpdocs-old
14M     site-backups
73M     logs
284K    old.site.com
20K     var

As you can see space usage is clearly shown by folder and in human readable text i.e. MB, GB etc.

If you want to just show the top 10 items ordered by size you can use this:

du -hsx * | sort -rh | head -10

Where, du command -h option : display sizes in human readable format (e.g., 1K, 234M, 2G). du command -s option : show only a total for each argument (summary). du command -x option : skip directories on different file systems. sort command -r option : reverse the result of comparisons. sort command -h option : compare human readable numbers. This is GNU sort specific option only. head command -10 OR -n 10 option : show the first 10 lines.

The above command will only work of GNU/sort is installed. Other Unix like operating system should use the following version (see comments below):

This article was last modified: Feb. 19, 2016, 11:25 a.m.


Please log in to leave a comment.

Add or change tags.

A comma-separated list of tags.


Hacker News