#!/bin/bash
# http://crystalfaeries.net/posix/bin/duhome
# celeste:crystalfaery 2013-02-04 16:38:48+00:00
# compute .du.txt files for each directory we have in our home directory
# and for each directory symlinked from our home directory
let limit=0	# default in case no command-line arguments
while [[ $# -gt 0 ]]
do
	let limit=$1
	shift	# use the last argument tossing all preceeding ones
done
let i=-1
while [[ $i -lt $limit ]]
do
	let i+=1	# indexing from 0 through $limit
	for d in $( find . -maxdepth 1 -type d -o -type l );
	do	# uncomment the version you prefer to {en,dis}able progress to console
	# progress version:
		echo "`/usr/local/bin/now` ======= depth $i sizes of `pwd` ======= begin"	| tee    $d/.du.txt		|| continue
		du --max-depth="$i" $d/ 2>/dev/null | sort -rn					| tee -a $d/.du.txt | head	|| continue
		echo "`/usr/local/bin/now` ======= depth $i sizes of `pwd` ======= end"		| tee -a $d/.du.txt		|| continue
	# silent version:
	#	echo "`/usr/local/bin/now` ======= depth $i sizes of `pwd` ======= begin"	>	 $d/.du.txt		|| continue
	#	du --max-depth="$i" $d/ 2>/dev/null | sort -rn					>>	 $d/.du.txt		|| continue
	#	echo "`/usr/local/bin/now` ======= depth $i sizes of `pwd` ======= end"		>>	 $d/.du.txt		|| continue
	done
done
exit $?


syntax highlighted by Code2HTML, v. 0.9.1