×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to Sum file sizes for a particular File type

How to Sum file sizes for a particular File type

How to Sum file sizes for a particular File type

(OP)
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.




 

RE: How to Sum file sizes for a particular File type

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
http://bshtele.com

RE: How to Sum file sizes for a particular File type

(OP)
Thank you very much AvayaTier3...
It works beautifully, I will create a job so that I can get a daily email with the info.

RE: How to Sum file sizes for a particular File type

Here is a shell script that I named ls_awk.sh and it accepts optional wildcards that gets passed to the ls 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:

Prompt> ls_awk.sh *.gz
7195185
30050
30050
30050

1556
1853
ttl size  2424899463 . GB: 2

 

RE: How to Sum file sizes for a particular File type

CODE

ls -l DBS* | awk '{sum += $5}; END {print sum}'

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close