Two-cent Tip: How big is that directory? [Linux Gazette No. 172, 2-Cent tips.] This material can also be downloaded from the Linux Gazette site at :: http://linuxgazette.net/172/lg_tips.html. Follow the discussion that this posting triggered off. You can see an improve version of my script, near the end of this page. Dr. Parthasarathy S [drpartha at gmail.com] Tue, 2 Feb 2010 09:57:02 +0530 At times, you may need to know exactly how big is a certain directory (say top directory) along with all its contents and subdirectories(and their contents). You may need this if you are copying a large diectory along with its contents and structure. And you may like to know if what you got after the copy, is what you sent. Or you may need this when trying to copy stuff on to a device where the space is limited. So you want to make sure that you can accomodate the material you are planning to send. Here is a cute little script. Calling sequence:: howmuch You get a summary, which gives the total size, the number of subdirectories, and the number of files (counted from the top directory). Good for book-keeping. ###########start-howmuch-script # Tells you how many files, subdirectories and content bytes in a # directory # Usage :: how much # check if there is no command line argument if [ $# -eq 0 ] then echo "You forgot the directory to be accounted for !" echo "Usage :: howmuch " exit fi echo "***start-howmuch***" pwd > ~/howmuch.rep pwd echo -n "Disk usage of directory ::" > ~/howmuch.rep echo $1 >> ~/howmuch.rep echo -n "made on ::" >> ~/howmuch.rep du -s $1 > ~/howmuch1 tree $1 > ~/howmuch2 date >> ~/howmuch.rep tail ~/howmuch1 >> ~/howmuch.rep tail --lines=1 ~/howmuch2 >> ~/howmuch.rep cat ~/howmuch.rep # cleanup rm ~/howmuch1 rm ~/howmuch2 #Optional -- you can delete howmuch.rep if you want #rm ~/howmuch.rep echo "***end-howmuch***" #########end-howmuch-script There is an improved (but less readable) version of the script. Here, we do NOT use any temp. files. Thanks to Ben Okopnik (Chief Editor LG) for the suggestion, and the new script. ##########improved howmuch start #!/bin/bash # Created by Ben Okopnik on Wed Feb 3 21:57:05 EST 2010 [ -d "$1" ] || { printf "Usage: ${0##*/} \n"; exit; } pwd echo -e "Disk usage of directory ::$1\nmade on ::`date`" du -sk "$1" # You could use 'tree "$1"|sed -n "$p"' - or stick with the standard toolkit ls -lR "$1"|awk '/^\//{d++};/^-/{f++}END{print d-1" directories, "f" files"}' ##########improved howmuch end