#!/data/data/com.termux/files/usr/bin/bash
#                       /usr/local/bin/dudir
# https://crystalfaeries.net/posix/bin/dudir
# celeste:crystalfaery DUDIR Thu, 11 May 2017 22:22:56 UTC
# "du" (disk usage) of a  "dir" (directory tree)
#            sorted in descending order of size

touch					.du.txt .tree.txt
if    [ $? -ne 0 ]
then
	echo "$0 ERROR: Require Permissions to write .du.txt and .tree.txt"				1>&2
	sudo touch			.du.txt .tree.txt
	sudo chmod 660			.du.txt .tree.txt
	sudo chown `whoami`:staff	.du.txt .tree.txt	# your CONFIG may prefer different user:group
fi
if    [ $# -eq 0 ]
then	# if no command-line arguments (dirs) then do only cwd
	pwd												>  .tree.txt
	tree -aidFlRx -du --dirsfirst	| tail -n +2							>> .tree.txt&
	df									>  .du.txt
	du -L -s    -x $(pwd)/		| sed 's/[0-9][0-9][0-9]	/M	/g ; s/\/$/:/'		>> .du.txt
	du -L -a    -x 			| sed 's/\.\///g' | sort -rn | grep -v '.*\/$'			>> .du.txt
	exit
fi
while [ $# -gt 0 ]
do	# for each directory listed on the command line
	cd	${1}	||	exit 1
	pwd												>  .tree.txt
	/usr/bin/tree -dx		| tail -n +2							>> .tree.txt&
	/usr/local/bin/df --full									>  .du.txt
	du -L -s    -x $(pwd)/		| sed 's/[0-9][0-9][0-9]	/M	/g ; s/\/$/:/'		>> .du.txt
	du -L -a -S -x 			| sed 's/\.\///g' | sort -rn | grep -v '.*\/$'			>> .du.txt
	shift	# next command-line argument
done



syntax highlighted by Code2HTML, v. 0.9.1