Visit Our UNIX and Linux User Community

Help with calculating size of files.

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with calculating size of files.
# 1  
Old 08-27-2009
Question Help with calculating size of files.

Hi All,

I am very new to shell scripting. I have a text file which is the output of another utility. This text file has a list of SAF files which is basically a list of orphan attachments in the attachments directory. Now I want to read each file name from the file, get its size and repeat this to all files to get the total size of all the files listed together. This will help us know the amount of space these currently occupying. Any help would be highly appreciated.

Thanks in advance.

# 2  
Old 08-27-2009
Please post a small sample of your input file.
# 3  
Old 08-28-2009
Hi radoulov,

Here is a sample from the input file:


The values CURRENT, ORPHAN represent the status of the files in the attachments directory.I want to add the size of all the files.

Many thanks for your help.

# 4  
Old 08-28-2009
Using ls -l option for each file check the size and can accumulate for all the files.
# 5  
Old 08-28-2009
In your file the first column is the name of file? in this case:

awk '{ print $1}' | du -s

# 6  
Old 08-28-2009
Mate I have got what you need as i've been working with backup size issues recently so I assume that you want to calculate size of some spesific files (i give 3 example of file u change them according to extension of your files) and besides lets say u want to consider the modification date of files ( for ex:files that are created earlier than 3 days):

find . \( -name "*.gz" -o -name "*.tar" -o -name "*.rar" \) -mtime -3 -exec ls -l {} \;| awk '/^-/ {total += $5} END {printf "%15.0f\n",total}'

$5 in awk represents the 5th column (size column) that is result of "ls -l" command.


Last edited by EAGL€; 08-28-2009 at 07:14 AM..
# 7  
Old 08-28-2009
With Perl:

perl -ane'
  $t += -s $F[0];
  printf "%.2fK\n", $t/1024 if eof
  ' infile

Previous Thread | Next Thread
Test Your Knowledge in Computers #307
Difficulty: Easy
The common software-programming acronym 18N comes from the term Interlocalization;.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Calculating size of backups

hi everyone i have posted this query but i dont where it has gone i am posting again . my issue is that i have many backup files in a backup nfs share and i need to calculate it size just by adding their individual file sizes which is repetitive jobs. so is there any command or variation of du... (1 Reply)
Discussion started by: janakors
1 Replies

2. UNIX for Beginners Questions & Answers

Calculating size of backups

hi everyone i have a backup share mounted with me on solaris 10 which have daily backups. everyday i need to calculate all individual sizes of files and need to report somewhere. e.g i have .rman 7backup files daily . what i need that is there any commnd or variation of du command which can add... (1 Reply)
Discussion started by: janakors
1 Replies

3. Shell Programming and Scripting

Calculating average from files

I have some files with the following contents.I would like to calculate average of fifth column. How can I do this with awk? file1 cat 95.9 152 78.0 17.9 rat 67.1 153 36.5 30.6 dog 81.4 154 68.1 13.3 dog 92.0 155 55.5 36.5 rat 73.8 156 23.9 49.9 file2 rat... (4 Replies)
Discussion started by: avina
4 Replies

4. Shell Programming and Scripting

Calculating average of 100 different files of same size

Hey guys..... I have many files (lets say 100 or more) of same size, and I want to create a new output file and calculate the average of first row fifth column in all files and print it in first row of output file, then 2nd row fifth col in all 100 files and print it in 2nd row of output... (1 Reply)
Discussion started by: CAch
1 Replies

5. AIX

calculating the size of the luns using script

Hi This is the lspv output of my server : cbspsdb01 #lspv hdisk0 00c7518d2d512fd4 cdgvg active hdisk1 00c7518d2dcbc9d6 cdgvg active hdisk2 00c7518dcda9199a appvg active hdisk3... (1 Reply)
Discussion started by: samsungsamsung
1 Replies

6. UNIX for Dummies Questions & Answers

CAlculating page file size

hello dont know if this is the correct forum for this post but i have a question. i am revising for a exam on operating systems and i have the question... A system has a 32bit virtual address divided into 2kbyte pages and each entry in the page table is 6 bytes in length. what is the size... (0 Replies)
Discussion started by: Fortune
0 Replies

7. Shell Programming and Scripting

compare files and calculating

Hi everybody: Could anybody tell me how can I do this task in AWK language. I've two files (file1 & file2) where file1 its last row it has first field value equal that the first row in file2, thyen I want calculate the difference in other fields, and this values apply in file2. This is: file1:... (6 Replies)
Discussion started by: tonet
6 Replies

8. Programming

calculating size of int

Hi, Is there any way to calculate the size of a built in data type without using 'sizeof' operator? I also don't have the option to read it from std .h file. regards Apoorva Kumar (10 Replies)
Discussion started by: apoorvasharma80
10 Replies

9. 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

10. Shell Programming and Scripting

Scripts for calculating size and remaining space of a directory automatically.

I would like to create a script for calculating size and remaining space of a directory automatically every 24 hours, then send an email to report to the admin. * POSIX and PERL are preferred. Can anyone help, please? (1 Reply)
Discussion started by: leonall
1 Replies

Featured Tech Videos