Summing file sizes | Unix Linux Forums | UNIX Desktop for Dummies Questions & Answers

  Go Back    


UNIX Desktop for Dummies Questions & Answers Discuss UNIX and Linux user interfaces like GNOME, KDE, CDE, and Open Office here. All UNIX and Linux Newbies Welcome !!

Summing file sizes

UNIX Desktop for Dummies Questions & Answers


Tags
file size find ls

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-01-2012
Alexander4444 Alexander4444 is offline
Registered User
 
Join Date: Apr 2010
Last Activity: 25 January 2013, 12:43 PM EST
Posts: 12
Thanks: 6
Thanked 0 Times in 0 Posts
Summing file sizes

I was just curious about how to sum the total file size of a certain type of file. For instance:


Code:
$find . -name "*.aif"

will print out the paths to each .aif file. Instead of printing, how could one sum the total space used by all of the aif files? Thanks!
Moderator's Comments:
Please use code tags

Last edited by jim mcnamara; 12-01-2012 at 08:49 AM..
Sponsored Links
    #2  
Old 12-01-2012
bartus11's Avatar
bartus11 bartus11 is offline Forum Staff  
Moderator
 
Join Date: Apr 2009
Last Activity: 23 November 2014, 6:49 AM EST
Posts: 3,720
Thanks: 7
Thanked 1,147 Times in 1,118 Posts
Try:
Code:
find . -name "*.aif" -ls | awk '{s+=$7}END{print s/(1024*1024)" Mbytes"}'

The Following User Says Thank You to bartus11 For This Useful Post:
Alexander4444 (12-03-2012)
Sponsored Links
    #3  
Old 12-01-2012
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 21 November 2014, 11:17 AM EST
Location: Galactic Empire
Posts: 3,389
Thanks: 235
Thanked 1,210 Times in 1,136 Posts

Code:
find . -name "*.aif" -exec ls -l {} \; | awk ' { s+=$5 } END { printf "%d bytes\n", s } '

The Following User Says Thank You to Yoda For This Useful Post:
Alexander4444 (12-03-2012)
    #4  
Old 12-03-2012
Alexander4444 Alexander4444 is offline
Registered User
 
Join Date: Apr 2010
Last Activity: 25 January 2013, 12:43 PM EST
Posts: 12
Thanks: 6
Thanked 0 Times in 0 Posts
Thanks!

Thanks for these explanations! They work excellently. I especially appreciate the nice formatting of the output in Mb.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Summing lines in a file LearningLinux2 UNIX for Dummies Questions & Answers 6 10-15-2012 09:03 AM
HELP with Unix scripts in summing columns in a file ramneim Homework & Coursework Questions 12 08-21-2012 04:54 PM
summing up the fields in fixed width file srilaxmi Shell Programming and Scripting 2 04-07-2009 03:01 AM
Summing file size and output ramkrix UNIX for Advanced & Expert Users 1 11-12-2008 01:30 PM
Summing the columns of a file asahlot Shell Programming and Scripting 3 09-24-2008 10:18 PM



All times are GMT -4. The time now is 11:56 AM.