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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
calculate from three files koti_rama Shell Programming and Scripting 5 01-08-2008 09:27 AM
bash script working for small size files but not for big size files. davidpreml Shell Programming and Scripting 1 11-01-2006 11:06 AM
calculate directory size by year of file igidttam UNIX for Dummies Questions & Answers 11 09-25-2006 07:40 PM
How to calculate file's size in directory and subdirectory KLL Shell Programming and Scripting 4 10-16-2003 07:02 AM
how to calculate the file size? rooh UNIX for Dummies Questions & Answers 3 08-17-2001 01:45 PM

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 07-21-2005
big123456 big123456 is offline
Registered User
  
 

Join Date: May 2005
Posts: 200
calculate size of some files

Hi,
1-I want to calculate the size of all files which are generated during last month in a directory. How can I do that ?
Of cours, I find them by :
$ls -l | grep jun
but how to calculate the sum of their size ?
2- the same but for all files generated last month and before that.
many thanks before.
  #2 (permalink)  
Old 07-21-2005
pixelbeat pixelbeat is offline
Registered User
  
 

Join Date: Jun 2005
Location: Ireland
Posts: 61
If you combine the following scripts you should get what you want:

http://www.pixelbeat.org/scripts/find_mm_yyyy
http://www.pixelbeat.org/scripts/add

The following might work straight off?

find_mm_yyyy 06 2005 -printf "%s\n" | add
  #3 (permalink)  
Old 07-21-2005
big123456 big123456 is offline
Registered User
  
 

Join Date: May 2005
Posts: 200
thank you.
I want to find all from may 2005
For the first I have this problem :
$altest
Usage: altest MM YYYY
$altest 05 2005
date: illegal option -- -
date: illegal option -- t
date: illegal option -- c

How should I enter the date then ?
Thanks.
  #4 (permalink)  
Old 07-21-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Quote:
Originally Posted by big123456
thank you.
I want to find all from may 2005
For the first I have this problem :
$altest
Usage: altest MM YYYY
$altest 05 2005
date: illegal option -- -
date: illegal option -- t
date: illegal option -- c

How should I enter the date then ?
Thanks.
the problem is that the script is using GNU-specific 'date' options. If you don't have GNU 'date' - you're out of luck with this script.

This is not bullet-proof, but.... [Solaris 9 stock 'ls']
Code:
ls -lrt | nawk '$6 == "Jun" {sum+=$5} END{print sum}'
If you need a better solution, you would need to use 'find' with '-newer' options. You might wanna search FAQs for more leads/options.

Last edited by vgersh99; 07-21-2005 at 12:03 PM..
  #5 (permalink)  
Old 07-21-2005
becket's Avatar
becket becket is offline
Registered User
  
 

Join Date: Jul 2005
Location: Liege / Belgium
Posts: 36
Code:
sum=0 
for filesize in  $(  ls -la |grep $(date -d '1 month ago' +%Y-%m )|awk '{print $5}'  ) 
do 
   let sum=sum+filesize 
done 
echo sum $sum
  #6 (permalink)  
Old 07-21-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Quote:
Originally Posted by becket
Code:
sum=0 
for filesize in  $(  ls -la |grep $(date -d '1 month ago' +%Y-%m )|awk '{print $5}'  ) 
do 
   let sum=sum+filesize 
done 
echo sum $sum
Again - this is GNU-based AND you're using grep AND awk all in one - in most cases it's considered UUOG
  #7 (permalink)  
Old 07-22-2005
big123456 big123456 is offline
Registered User
  
 

Join Date: May 2005
Posts: 200
thank you. but it gives me :
date: illegal option -- d
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
Any way how can I format date to have just last month ? Thank you.
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 11:41 AM.


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