In my day job as a Systems Engineer I frequently find myself switching between different UNIX and Linux distributions. While many of the commands exist on both sides of the aisle, I often find vast differences in the command line parameters that can be consumed by a given command when used in, for example, Linux vs Solaris.
Recently I came upon this again with the need to easily ferret out the majority consumer of drive space on a Solaris 10 system. While we did have the xpg4 specification support available, the du command was still missing my favorite option “max-depth”.
In Linux I use this to limit the output to only the current directory level so that I don’t have to face to possibility of wading through a tremendously large listing of sub-directories to find the largest directory in the level I am in. Unfortunately, in Solaris, even with xpg4, the du command doesn’t have this option, so my solution was to pipe the results through egrep and use that to filter out the sub-directories.
Here is some example output from a RedHat Linux 5.11 server:
[root@atl4cmweb01 var]# du -h
Here is the same example ouput from the RedHat server using the max-depth option:
[root@atl4cmweb01 var]# du -h --max-depth=1
Here is the command example run without my egrep mod in Solaris 10:
[root@atl4sfsbatchb log]# /usr/xpg4/bin/du -h
And here is the improved command output using my egrep mod on the same Solaris server:
[root@atl4sfsbatchb log]# /usr/xpg4/bin/du -hx | egrep -v '.*/.*/.*'