The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to List out the Files based on the file Size...? psiva_arul Shell Programming and Scripting 6 04-08-2008 11:06 PM
command to list file size rgordon HP-UX 3 12-05-2007 05:43 AM
command to find out total size of a specific file size (spread over the server) abhinov SUN Solaris 3 08-08-2007 07:48 AM
List File size komputersman UNIX for Dummies Questions & Answers 10 06-13-2007 05:39 PM
total size taken by directory jyoti HP-UX 2 04-12-2006 05:52 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-21-2008
tekster757 tekster757 is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 33
Total file size of a subset list

Hello!

I'm trying to find out the total file size of a subset list in a directory. For example, I do not need to know the total file size of all the files in a directory, but I need to know what the total size is of say, "ls -l *FEB08*" in a directory. Is there any easy way of doing this?

Thank you,
  #2 (permalink)  
Old 03-21-2008
matt.d's Avatar
matt.d matt.d is offline
Registered User
  
 

Join Date: Feb 2008
Location: /dev/null
Posts: 62
I think this will do it (unless I'm missing something...it is almost lunch )

Code:
ls -lt *FEB08* | awk '{tot += $5} END {tot=tot/1024 ; printf(" TOTAL SIZE (kb): 
 %4.2f\n",tot)}'
  #3 (permalink)  
Old 03-21-2008
tekster757 tekster757 is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 33
Total file size of a subset list

Thank you! Yes, that worked very well. But now I'm curious about a couple of things (i.e., please explain a little of how it works):

Instead of bothering you with even more questions than, I looked awk in google and found gnu.org and searched on +=. It gave me this:

ls -l files | awk '{ x += $5 }
END { print "total K-bytes: " (x + 1023)/1024 }'

1. Should I be using the (x + 1023)/1024 stated above (I'm wondering why they have that)?
2. I have GB of files, is there a different number I can use to get GB or do I just add 2 zero's?
3. Why %4.2f\n (what does that mean)?

Thanks!
  #4 (permalink)  
Old 03-21-2008
matt.d's Avatar
matt.d matt.d is offline
Registered User
  
 

Join Date: Feb 2008
Location: /dev/null
Posts: 62
1. Not sure why they are using 1023, quite frankly.

2. If you have GB of files, divide x (or tot in my example) by 1073741824

3. %4.2f\n:

% is prefix to a format code
4 means four places to left of decimal
. format number with a decimal
2 means two places to right of decimal
f means end of format code
\n newline
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0