Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Jun 1997 22:07:15 -0500 (CDT)
From:      "Lee Crites (AEI)" <leec@adam.adonai.net>
To:        Tim Moony <timm@uniqsite.com>
Cc:        questions@FreeBSD.ORG
Subject:   Re: Size of all files
Message-ID:  <Pine.BSF.3.95.970605220302.23336A-100000@adam.adonai.net>
In-Reply-To: <Pine.BSF.3.96.970605174711.20753A-100000@uniqsite.com>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
On Thu, 5 Jun 1997, Tim Moony wrote:

=>Sorry if this question is stupid.

The only stupid question is the one unasked...  (imnsho)

=>Which command can tell me the total size of all files in a directory tree? 

I'm not sure what you are looking for exactly, but I have a script and
awk file which give me something like what you are asking for.

----- hmr script -----
#!/bin/csh -f
# Get a listing (using ls -AlR) and pass it into hmr.awk
ls -AlR $* | awk -f $0.awk
----- end of hmr script

----- hmr.awk script -----
# Add up the size of each file information passed in (in ls -l format)
# and report the number of items and total size of all items combined.
BEGIN {
  cnt = 0
  tot = 0
}
{
  link = $11
  size = $5
  if (link == "") {
    if (size != "") {
      cnt++
      tot += $5
      }
    }
}
END{
  printf("%d items, %d bytes", cnt, tot)
  if (tot > (8 * 1024)) {
    printf(" (%.2fK)", (tot/1024))
    }
  if (tot > (1024 * 1024)) {
    printf(" (%.2fM)", (tot/(1024*1024)))
    }
  printf("\n")
}
----- end of hmr.awk script -----

Lee




Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.95.970605220302.23336A-100000>