alias dud='du -chd 1' alias dud2='du -chd 2' alias dud3='du -chd 3' alias dud4='du -chd 4' alias duds='du -chd 1 | sort -h' alias duds2='du -chd 2 | sort -h' alias duds3='du -chd 3 | sort -h' alias duds4='du -chd 4 | sort -h'
Now on a system where -d doesnt work you need to use –max-depth instead:
alias dud='du -ch --max-depth 1' alias dud2='du -ch --max-depth 2' alias dud3='du -ch --max-depth 3' alias dud4='du -ch --max-depth 4' alias duds='du -ch --max-depth 1 | sort -h' alias duds2='du -ch --max-depth 2 | sort -h' alias duds3='du -ch --max-depth 3 | sort -h' alias duds4='du -ch --max-depth 4 | sort -h'
SIDENOTE: check this out Article on finding largest files and folders
So the above commands are useful to recursively measure the size of directories. Note the dud commands can be thrown in together with an “-x” argument to stay within the filesystem.
dud -x dud1 -x dud2 -x dud3 -x dud4 -x
Here are some example outputs of all of the above commands:
###################### ##### du depth 1 ##### ###################### # dud 0 ./opt 63M ./backups 0 ./agentx 0 ./local 121M ./log 8.0K ./spool 0 ./mail 223M ./cache 64M ./lib 0 ./tmp 4.0K ./www 8.0K ./netatalk 36M ./cores 0 ./ftp 660K ./readynasd 8.0K ./readydrop 0 ./replicate 505M . 505M total ############################# ##### du depth 1 sorted ##### ############################# # duds 0 ./agentx 0 ./ftp 0 ./local 0 ./mail 0 ./opt 0 ./replicate 0 ./tmp 4.0K ./www 8.0K ./netatalk 8.0K ./readydrop 8.0K ./spool 660K ./readynasd 36M ./cores 63M ./backups 64M ./lib 121M ./log 223M ./cache 505M . 505M total ############################# ##### du depth 2 sorted ##### ############################# # duds2 0 ./agentx 0 ./cache/apache2 0 ./cache/forked-daapd 0 ./cache/git 0 ./cache/man 0 ./ftp 0 ./lib/dbus 0 ./lib/ftp 0 ./lib/initscripts 0 ./lib/insserv 0 ./lib/libuuid 0 ./lib/misc 0 ./lib/nfs 0 ./lib/nut 0 ./lib/python 0 ./lib/systemd 0 ./lib/update-rc.d 0 ./lib/urandom 0 ./lib/vim 0 ./local 0 ./log/fsck 0 ./log/news 0 ./log/sysstat 0 ./mail 0 ./netatalk/CNID 0 ./opt 0 ./replicate 0 ./replicate/shm 0 ./spool/netatalk 0 ./tmp 4.0K ./lib/btrfs 4.0K ./lib/mdadm 4.0K ./lib/sudo 4.0K ./spool/cron 4.0K ./www 8.0K ./lib/snmp 8.0K ./netatalk 8.0K ./readydrop 8.0K ./spool 16K ./cache/ldconfig 20K ./lib/connman 24K ./lib/pam 24K ./lib/ucf 28K ./cache/fontconfig 36K ./log/apache2 100K ./log/apt 156K ./log/readynasd 440K ./cache/samba 456K ./log/samba 660K ./readynasd 1.8M ./cache/debconf 2.2M ./backups/md 2.5M ./backups/readynasd 2.6M ./lib/samba 3.7M ./log/frontview 14M ./lib/dpkg 18M ./lib/gems 30M ./lib/apt 32M ./log/journal 36M ./cores 63M ./backups 64M ./lib 83M ./log/atop 121M ./log 221M ./cache/apt 223M ./cache 505M . 505M total ########################################## ##### du depth 1 within 1 filesystem ##### ########################################## # Notice how since /data is a different subvolume (btrfs filesystem here), then /data/home and /data/so-and-so, so all of those so-and-so (home as well) ones show up as 0 size. Because we are staying within the /data filesystem (as we are in /data when we run "dud -x"). And each subvolume behaves as its own filesystem with btrfs. /data# dud -x 0 ./home 0 ./.apps 0 ./.vault 0 ./._share 0 ./.purge 0 ./Main 0 ./readydrop 0 ./.timemachine 36K . 36K total # Here is the same command but letting du flow freely into any filesystem (subvolume), so it measures all of the sizes. /data# dud 0 ./home 2.2M ./.apps 0 ./.vault 64K ./._share 0 ./.purge 2.7T ./Main 0 ./readydrop 0 ./.timemachine 2.7T . 2.7T total