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.

Cheers,
Rajesh.

Please post a small sample of your input file.

Hi radoulov,

Here is a sample from the input file:

S_XL_VIEW_MAP_04-BWNTG_04-1JFF.SAF CURRENT
S_XL_VIEW_MAP_04-BWNTI_04-1JFG.SAF CURRENT
S_DOC_PPSL_0-7VC8N_0-2AQ.SAF CURRENT
S_DOC_PPSL_0-8WGZ_0-DK.SAF ORPHAN
S_DOC_PPSL_0-A41Q_0-FI.SAF ORPHAN

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.

Cheers,
Rajesh.

Using ls -l option for each file check the size and can accumulate for all the files.

In your file the first column is the name of file? in this case:

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

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.

regards

With Perl:

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