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:
[code language=”bash” gutter=”false”]
[[email protected] var]# du -h 8.0K ./games 8.0K ./run/saslauthd 8.0K ./run/lvm 8.0K ./run/setrans 8.0K ./run/ppp 8.0K ./run/snmpd 4.0K ./run/mysqld 8.0K ./run/pm 8.0K ./run/dbus 8.0K ./run/nscd 8.0K ./run/console 8.0K ./run/sudo 8.0K ./run/netreport 176K ./run 8.0K ./yp/binding 24K ./yp 8.0K ./lib/games 8.0K ./lib/mysql 4.0K ./lib/nfs/statd/sm.bak 8.0K ./lib/nfs/statd/sm 24K ./lib/nfs/statd 8.0K ./lib/nfs/v4recovery 0 ./lib/nfs/rpc_pipefs/statd 0 ./lib/nfs/rpc_pipefs/portmap 0 ./lib/nfs/rpc_pipefs/nfs/clntf 0 ./lib/nfs/rpc_pipefs/nfs/clnt5 0 ./lib/nfs/rpc_pipefs/nfs/clnt0 0 ./lib/nfs/rpc_pipefs/nfs 0 ./lib/nfs/rpc_pipefs/mount 0 ./lib/nfs/rpc_pipefs/lockd 0 ./lib/nfs/rpc_pipefs 40K ./lib/nfs 8.0K ./lib/dhclient 8.0K ./lib/iscsi/isns
[/code]
Here is the same example ouput from the RedHat server using the max-depth option:
[code language=”bash” gutter=”false”]
[[email protected] var]# du -h –max-depth=1 8.0K ./games 176K ./run 24K ./yp 22M ./lib 32K ./empty 1.5G ./log 12K ./account 236K ./opt 24K ./db 8.0K ./nis 2.9M ./tmp 8.0K ./tmp-webmanagement 40K ./lock 8.0K ./preserve 8.0K ./racoon 16K ./lost+found 1.4M ./spool 8.0K ./net-snmp 83M ./cache 8.0K ./local 1.6G .
[/code]
Here is the command example run without my egrep mod in Solaris 10:
[code language=”bash” gutter=”false”]
[[email protected] log]# /usr/xpg4/bin/du -h 25K ./webconsole/console 26K ./webconsole 1K ./pool 1K ./swupas 2K ./ilomconfig 1K ./current/ras1_sfsuperbatchb 1K ./current/od1_atl4sfsuperbatchb 4.3G ./current/ras1_atl4sfsbatchb 2.1G ./current/od1_atl4sfsbatchb 560K ./current/avs 2K ./current/ebaps/output 9.3M ./current/ebaps 4.0M ./current/psh 3.1M ./current/autoresponder 5K ./current/fdms_download 29K ./current/fdms_server 109K ./current/fmt 5K ./current/paris/output 653K ./current/paris 1K ./current/od1_sfsuperbatchb 28K ./current/ccTemplateLoader 633K ./current/ccTemplateLoaderLegacy 15M ./current/whinvoices 1K ./current/appmonitor.prod.netsol.com 132M ./current/chase 6.6G ./current 160K ./archive/ccTemplateLoader 1K ./archive/od1_atl4sfsuperbatchb 4.9M ./archive/avs 1K ./archive/ebaps/output 26M ./archive/ebaps 881M ./archive/psh 1014M ./archive/autoresponder 1K ./archive/fdms_download 6.8M ./archive/fdms_server 21M ./archive/paris 1K ./archive/ccTemplateLoaderLegacy 4.1G ./archive/ras1_atl4sfsbatchb 3.1G ./archive/od1_atl4sfsbatchb 5.9G ./archive/chase 102M ./archive/whinvoices 15G ./archive 22G .
[/code]
And here is the improved command output using my egrep mod on the same Solaris server:
[code language=”bash” gutter=”false”]
[[email protected] log]# /usr/xpg4/bin/du -hx | egrep -v ‘.*/.*/.*’ 26K ./webconsole 1K ./pool 1K ./swupas 2K ./ilomconfig 6.6G ./current 15G ./archive 22G .
[/code]