There are occasions when using a Linux or Unix operating system when it is gobsmacking how a two letter command can do so much. And so it is the case with our use of the “du” to display disk usage statistics via the incarnation …
$ du -a /
… to display a whole disk from its root directory ( / ) and up, reporting on the disk usage for all the files it encounters.
Putting this in context for how it could be useful to track down, perhaps, major inode usage (ie. lots of files being created) somewhere. In this scenario we say that we might want to narrow the search to the top 15 files (which are perhaps directories, as you might know from your Unix and/or Linux training) via …
$ du -a / 2> /dev/null | sort -n -r | head -15
… and on our local MAMP web server (of a MacBook Pro) we got
$ du -a / 2> /dev/null | sort -n -r | head -15
463218232 /
183397888 /Users
183393240 /Users/user
173735704 /Library
155636160 /Library/pgAgent
139676416 /Users/user/Desktop
139661920 /Users/user/Desktop/NS15148
109587848 /Users/user/Desktop/NS15148/robertmetcalfe
66994504 /Library/pgAgent/Downloads
48401968 /Applications
44435304 /Library/pgAgent/Library
27955056 /Users/user/Desktop/NS15148/robertmetcalfe/Downloads
27639928 /opt
26857192 /opt/local
26839216 /Library/pgAgent/VirtualBox VMs
… and just to put a little intelligence into this have a look at the “file” command as a means to show a file type, and the marvellous “awk” integration of all this via its “system()” method …
$ du -a / 2> /dev/null | sort -n -r | head -15 | awk -F"\t" '{ print $1, FS, system("file \"" $2 $3 $4 $5 "\""); }' | grep -v '^[0| ]' | sed '/:/s// ... is a/g'
463218232 / ... is a directory
183397888 /Users ... is a directory
183393240 /Users/user ... is a directory
173735704 /Library ... is a directory
155636160 /Library/pgAgent ... is a directory
139676416 /Users/user/Desktop ... is a directory
139661920 /Users/user/Desktop/NS15148 ... is a directory
109587848 /Users/user/Desktop/NS15148/robertmetcalfe ... is a directory
66994504 /Library/pgAgent/Downloads ... is a directory
48401968 /Applications ... is a directory
44435304 /Library/pgAgent/Library ... is a directory
27955056 /Users/user/Desktop/NS15148/robertmetcalfe/Downloads ... is a directory
27639928 /opt ... is a directory
26857192 /opt/local ... is a directory
26839216 /Library/pgAgent/VirtualBox VMs ... is a directory
If this was interesting you may be interested in this too.