How to find total MB of a directory plus all subdirectories

Vikram Goyal vikigoyal at gmail.com
Sun Mar 18 11:50:17 UTC 2007


On Sun, Mar 18, 2007 at 01:44:10PM +0530, Vikram Goyal wrote:

Please update the code, if you chose to use it. It'll run with spaces in
names also, just needed to quote...

#-CUT & PASTE---------------------------------------------------------
#/bin/bash

IGNORE='proc /dev /initrd /mnt'

# This script produces a list of dir size. Selects only MB and above entries.

# Arg is the dir name else pwd is selected
if [ -z "$1" ]; then
        SDIR=`pwd`
	OutPut=/tmp`pwd`
else
        SDIR=$1
	OutPut=/tmp/${USER}/${1}
fi

echo "Output file is ${OutPut}/dir-size.out"

mkdirhier "${OutPut}" && ls -lAR --si --ignore="${IGNORE}" "${SDIR}"|grep 'total' -B1|grep '^total[[:space:]][0-9\.]*[mMgG][[:space:]]*' -B1 >"${OutPut}/dir-size.out" 2>&1
echo -e "\nTotal Size Of Dir $SDIR" >>"${OutPut}/dir-size.out" 2>&1
du -ach "${SDIR}"|grep "[[:space:]]total$" >>"${OutPut}/dir-size.out" 2>&1

less "${OutPut}/dir-size.out" 
#-CUT & PASTE---------------------------------------------------------

-- 
vikram...
         ||||||||
         ||||||||
^^'''''^^||root||^^^'''''''^^
        // \\   ))
       //(( \\// \\
      // /\\ ||   \\
     || / )) ((    \\
-- 
today, n.:
	A nice place to visit, but you can't stay here for long.
-- 
 o
~|~
 =
Registered Linux User #285795




More information about the users mailing list