Looking for utility to show total size of files in directory

Looking for utility to show total size of files in directory

Post by James Fab » Tue, 21 Nov 1995 04:00:00



I am looking for a utility to show me the total size of all the files in a
directory, and all it's subdirecotries.  Does anyone know of such a utility?  
I once had one for BSDI 2.0, but can not find it nor it's source to try and
port over.

James Fabin

 
 
 

Looking for utility to show total size of files in directory

Post by John Stee » Thu, 23 Nov 1995 04:00:00



Quote:>I am looking for a utility to show me the total size of all the files in a
>directory, and all it's subdirecotries.  Does anyone know of such a utility?  
>I once had one for BSDI 2.0, but can not find it nor it's source to try and
>port over.
>James Fabin

James,

  Here's what I use:

#!/bin/sh
#
# mb - shows MB used by a directory (and all it's subdirs)
#
# usage: mb dirname

du -s $* | awk '{sum+=$1} END {print sum "K used."}'

--
/*
 * SteeleSoft Consulting    John Steele - Systems Analyst/Programmer

 *
 *  http://uptown.turnpike.net/~jsteele/
 */

 
 
 

Looking for utility to show total size of files in directory

Post by Brian Nie » Thu, 23 Nov 1995 04:00:00



>This is a UNIX question!!! Read the previous message I posted in
>this news group about this, please.
>But here's the answer:
>UNIX> ls -la | awk '{pt=pt+$4} END {print pt}'
>If it doesn't work (because of compatibility problems), try out this
>command line:
>UNIX> ls -la | awk '{pt=pt+$5} END {print pt}'

or alternatively, you could just use du which, I believe is a fairly
standard unix utility, and displays the number of blocks used by files
and directories.  See the man page for details.

-Brian

--
Brian Niece
School of Chemical Sciences                   465 Noyes Lab, Box 41-1
University of Illinois                        600 S. Mathews Ave.

 
 
 

Looking for utility to show total size of files in directory

Post by Michael Nels » Thu, 23 Nov 1995 04:00:00




-> >
-> >I am looking for a utility to show me the total size of all the files
-> in a
-> >directory, and all it's subdirecotries.  Does anyone know of such a
-> utility?  
-> >I once had one for BSDI 2.0, but can not find it nor it's source to
-> try and
-> >port over.
->
->     I'm not sure about this, but can't you do this:
->
->     ls -lR
->
->     and it will display the totals?  If not, just write a little C
-> program that strips out the # of bytes --- call it "num" --- and
-> totals them up:
->
->     ls - lR | num

        How 'bout using "du"?  That's exactly what it does.

                Michael
--

San Francisco, CA

 
 
 

Looking for utility to show total size of files in directory

Post by David Bourgi » Thu, 23 Nov 1995 04:00:00



> I am looking for a utility to show me the total size of all the files in a
> directory, and all it's subdirecotries.  Does anyone know of such a utility?
> I once had one for BSDI 2.0, but can not find it nor it's source to try and
> port over.

> James Fabin

This is a UNIX question!!! Read the previous message I posted in
this news group about this, please.

But here's the answer:
UNIX> ls -la | awk '{pt=pt+$4} END {print pt}'

If it doesn't work (because of compatibility problems), try out this
command line:
UNIX> ls -la | awk '{pt=pt+$5} END {print pt}'

Hope it helps,
--
                                              David

David Bourgin - UFR IMA (French University - Grenoble)
I'm a netsurfer, and as such a citizen of the world!

 
 
 

Looking for utility to show total size of files in directory

Post by Greg de Freita » Fri, 24 Nov 1995 04:00:00


Save this as duk (DiskUseK/bytes)
------8<----------
:
# Show disc usage in K
du $* | awk '
        {
        if ( $1 > 8192 )
                printf "%5ld Mbytes %s\n", $1 / 1024, $2
        else if ( $1 > 8 )
                printf "%5ld Kbytes %s\n", $1 , $2
        else
                printf "%5ld  bytes %s\n", $1 * 1024, $2
        } '
---------8<-------

--
Ciao 4 now,
Greg.
##################################################
#-To Live, To Love, To Learn, To Leave A Legacy.-#
#-------Marque Membership number 330796----------#
##################################################

 
 
 

Looking for utility to show total size of files in directory

Post by Bob Hau » Fri, 24 Nov 1995 04:00:00


|> I am looking for a utility to show me the total size of all the files in a
|> directory, and all it's subdirecotries.

Try 'du'.

---
 Bob Hauck                              Wasatch Communcations Group

 
 
 

Looking for utility to show total size of files in directory

Post by Henrik Soderstro » Sat, 25 Nov 1995 04:00:00


du on its own will list the whole thing. Below is a little script
file I use that will ONLY show the total - you can call it something
like "treesize" or whatever ...

The grep bit masks away all output except the bottom "total" line
(even if you happen to have any directory names with the string
"total" in them).

du -bc $1 | grep [[:space:]]total$

cheers  /Henrik

 
 
 

Looking for utility to show total size of files in directory

Post by Grant Edwar » Wed, 29 Nov 1995 04:00:00


: du on its own will list the whole thing. Below is a little script
: file I use that will ONLY show the total - you can call it something
: like "treesize" or whatever ...

: The grep bit masks away all output except the bottom "total" line
: (even if you happen to have any directory names with the string
: "total" in them).

: du -bc $1 | grep [[:space:]]total$

What's wrong with "du -bs" ?

--
Grant Edwards        | Microsoft isn't the   | Yow!  What a COINCIDENCE!
Rosemount Inc.       | answer. Microsoft     | I'm an authorized ``SNOOTS OF
                     | is the question, and  | THE STARS'' dealer!!