calculate size of some files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting calculate size of some files
# 1  
Old 07-21-2005
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  
Old 07-21-2005
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  
Old 07-21-2005
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  
Old 07-21-2005
Code:
ls -ltr | grep "Jun" | awk -F" " 'BEGIN { sum=0 } { sum+=$5 }END { print sum }'

Code:
ls -ltr | grep -v "Jul" | awk -F" " 'BEGIN { sum=0 } { sum+=$5 }END { print sum }'


Note : You may have to take care of 'year' part in the grep.
Just tune this based on your needs.
# 5  
Old 07-21-2005
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 01:03 PM..
# 6  
Old 07-21-2005
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

# 7  
Old 07-21-2005
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Du -sh command taking time to calculate the big size files

Hi , My linux server is taking more time to calculate big size from long time. * i am accessing server through ssh * commands # - du -sh * #du -sh * | sort -n | grep G Please guide me for fast way to find big size directories under to / partition Thanks (8 Replies)
Discussion started by: Nats
8 Replies

2. Programming

[c] How to calculate size of the file from size of the buffer?

Hi, Can I find size of the file from size of the buffer written? nbECRITS = fwrite(strstr(data->buffer, ";") + 1, sizeof(char), (data->buffsize) - LEN_NOM_FIC, fic_sortie); Thank You :) (1 Reply)
Discussion started by: ezee
1 Replies

3. Shell Programming and Scripting

Find a particular directory in multiple file systems and calculate total size

Hello : I need some help in writing a ksh script which will find a particular directory in all the file systems in a server and finally report the total size of the direcotry in all the file systems. Some thing like this.. find /u*/app/oracle -type d -name "product" -prune and then... (1 Reply)
Discussion started by: Sam1974
1 Replies

4. Shell Programming and Scripting

Calculate byte size of string

Hi, I have task to merge multiple XML's to one big XML. In doing this i have to calculate the byte size of each XML which i will be recieving as a string from a code and append all the recieved XML's to single file. The reason being the byte size and the offset will help me to extract only... (7 Replies)
Discussion started by: chetan.c
7 Replies

5. Shell Programming and Scripting

Shell script to calculate the size of files

Dear all, Please help me to write a script that can calculate the size of files. For example: I have a directory which contain thousands of files. I need to know the size of files that their name begin with abc_123 Thank all!! (4 Replies)
Discussion started by: hainguyen1402
4 Replies

6. Solaris

calculate sum size of files by date (arg list too long)

Hi, I wanted a script to find sum of files for a particular date, below is my script ls -lrt *.req | nawk '$6 == "Aug"' | nawk '$7 == "1"'| awk '{sum = sum + $5} END {print sum}' However, i get the error below /usr/bin/ls: arg list too long How do i fix that. Many thanks before. (2 Replies)
Discussion started by: beginningDBA
2 Replies

7. Shell Programming and Scripting

bash script working for small size files but not for big size files.

Hi, I have one file stat. Stat file contents are as follows: for example. H50768020040913,00260100,507680,13,0000000643,0000000643,00000,0000 H50769520040808,00260100,507695,13,0000000000,0000000000,00000,0000 H50770620040611,00260100,507706,13,0000000000,0000000000,00000,0000 Now i... (1 Reply)
Discussion started by: davidpreml
1 Replies

8. UNIX for Dummies Questions & Answers

calculate directory size by year of file

I need to calcualte the size of a directory by the year the files in that directory were created . For example the script will sum up, by year, the number of blocks for that directory and its' subdirectories for files created / accessed in that year. I need a report that would look like... (11 Replies)
Discussion started by: igidttam
11 Replies

9. Shell Programming and Scripting

How to calculate file's size in directory and subdirectory

Hi, I have written one script to calculate total space of all file in one directory, ignoring subdirectory, it works fine. Now, I've been trying to calculate all files which includes files in any subdirectories. I use recursive function to do this, but it can work only if there is only one... (4 Replies)
Discussion started by: KLL
4 Replies

10. UNIX for Dummies Questions & Answers

how to calculate the file size?

HI, Can somebody please tell me how many bytes make a KB & MB. ThANKS. Rooh.:( (3 Replies)
Discussion started by: rooh
3 Replies
Login or Register to Ask a Question