Comments on Linux du Command Tutorial for Beginners (10 Examples)
Sometimes, while working on the Linux command line, you might want to quickly know disk usage for a set of files or for a complete directory. There's a specific command line tool that lets you do this, dubbed du. In this tutorial, we will discuss the basics of this tool as well as the features it provides using easy to understand examples.
2 Comment(s)
Comments
my 'du' to get the output sorted by size and human size presentation ('awk' and 'sort' dependant) :
du --max-depth=1 -x -k | sort -n | awk 'function human(x) { s="KMGTEPYZ"; while (x>=1000 && length(s)>1) {x/=1024; s=substr(s,2)} return int(x+0.5) substr(s,1,1)"iB" } {gsub(/^[0-9]+/, human($1)); print}'
Good examples. I use this for finding who is using the most space, e.g. mail folders:
du -cks * |sort -nr | head -20