View Single Post

   
  #2 (permalink)  
Old 02-01-2008, 09:18 AM
Dan C
 
Posts: n/a
Default Re: Newbie Needs one Command

On Fri, 01 Feb 2008 03:37:53 +0000, Davoud wrote:

> I need to find a Linux/Unix command that will display a list of all of
> the directories, visible and hidden, on a hard drive, and the sizes of
> those directories. I *do* *not* want to see a list of the half million
> of so files on the drive, just directories. I've asked this question on
> other Unix and Linux forums and had all sorts of good people trying to
> be helpful, but no workable answers. Is this not doable, perhaps?


Sure it's doable. Here's a script:
Save it as "dt" (or whatever you'd like), make it executable, and enjoy.


#!/bin/bash

# Script Name: Directory Totals
# Purpose: List the total sizes of directories

TempFile="${HOME}/.Directory_Totals"

clear

if [ "$1" == "" ]; then

UseDir=$(pwd)

else

if [ -d "$1" ]; then

UseDir="$1"

else

echo "PROBLEM:"
echo "The directory \"$1\" does not exist !"
echo
exit 1

fi

fi

pushd "${UseDir}" >/dev/null

{

echo "Directory Totals: ${UseDir}"
echo

echo "#!/bin/bash" >${TempFile}
echo "du --one-file-system --human-readable --summarize --total -- " `\ls -A |awk '{ print "\""$0"\"" }'` >>${TempFile}
chmod u+x ${TempFile}
${TempFile}
rm -f ${TempFile}

echo

} 2>/dev/null |more

popd "${UseDir}" >/dev/null

# EOF


--
"Ubuntu" -- an African word, meaning "Slackware is too hard for me".

Reply With Quote