Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Sum file sizes for a particular File type 1

Status
Not open for further replies.

rocco

IS-IT--Management
Oct 30, 2001
106
CA
Does anybody know how to sum file sizes for a particular file type.

Sample
ls -l
-rw-r--r-- 1 sun6 ultra 56086528 Feb 17 03:00 DBSmaria
-rw-r--r-- 1 sun6 ultra 3504128 Feb 17 03:00 DBSanna
-rw-r--r-- 1 sun6 ultra 500766720 Feb 5 03:00 DBSdebbie

Whatever magical command would give me the total of the 3 files.
Command DBS*
560357376

Thank you all for viewing my thread.




 
Code:
sun-> ls -l DBS*
-rw-r--r--   1 sun6 ultra    56086528 Feb 17 03:00 DBSmaria
-rw-r--r--   1 sun6 ultra     3504128 Feb 17 03:00 DBSanna
-rw-r--r--   1 sun6 ultra   500766720 Feb  5 03:00 DBSdebbie

sun-> ls -l DBS* | awk '{print $5, $s += $5}' | tail -1 | cut -d\  -f2
560357376

A great teacher, does not provide answers, but methods to teach others "How and where to find the answers"

bsh

37 years Bell, AT&T, Lucent, Avaya
Tier 3 for 27 years and counting
 
Thank you very much AvayaTier3...
It works beautifully, I will create a job so that I can get a daily email with the info.
 
Here is a shell script that I named [tt]ls_awk.sh[/tt] and it accepts optional wildcards that gets passed to the [tt]ls[/tt] command; it is similar to what AvayaTier3 posted, but it also internally prints out a grand total line, with the grand total also listed in GB. Saves some time avoiding having to grab the second column of output via cut.

Code:
#!/usr/bin/ksh


if [ $# -eq 0 ]
then
        /usr/bin/ls -o | awk '{print $4;fs+=$4;} END {print "ttl size", fs, ". GB:", int(fs/1024/1024/1024)}'
else

        if [ -f $* ]
        then
                /usr/bin/ls -o $* | awk '{print $4;fs+=$4;} END {print "ttl size ", fs, ". GB:", int(fs/1024/1024/1024)}'
        else
                if [ $# -eq 1 ]
                then
                        echo File not found: $*
                else
                        echo Files not found: $*
                fi
        fi
fi

Example:
[tt]
Prompt> ls_awk.sh *.gz
7195185
30050
30050
30050
[…]
1556
1853
ttl size 2424899463 . GB: 2
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top