Find the sum of files created 5 days before

Hi,

I want to find the sum of all the files created 5 days ago and store it in a variable. (os is HP-UX)

can this be extracted from ls -l

Is there any other way of getting the sum of all the files created

sum of what - file size?

find /path/to/files -type f \( -mtime -5 -a -mtime +4 \)  -exec ls -s {} \; | awk '{sum+=($1 * 4096); END{print sum}'

I haven't been on HPUX in several years - the block size of files may not be 4096, you can determine that with

df /path/to/files

@jim@mcnamara
Block size in HP-UX is 512 bytes.

Not sure that "find" works because the two "-mtime" values are convergent.
Maybe you meant:

find /path/to/files -type f \( -mtime -6 -a ! -mtime -5 \)      ...

This will still give different results depending on what time of day it is run.

@bang_dba
Post is really ambiguous. Please explain and give examples with real dates of what files are included in the query (including examples of large files and of files created at various times of the day). Please also explain what it is you want to "sum".

I am using the following code to get the result. But some how i am getting -ve values. Not sure why this is happening.

#!/bin/ksh
u05=0
for k in `find /u05/backup/ -type f -mtime -5 -print -exec ls -l {} \+ | awk '{print $5}';`
do
   u05=$((u05+k))
   echo $k
   echo $u05
echo "---------"
done
echo "Total file size is $u05"


Output

750
750
---------
11116650496
-1768250642
---------
11595284480
1237099246
---------
13440557056
1792754414
---------
10975354880
-116792594
---------
8705179648
-1547538
---------
9481904128
890421998
---------
--
---
----
----
Total file size is 1934451438

The largest number which can be used in Shell arithmetic is:
((2*1024*1024*1024) -1 ) = 2147483647
In file size terms this is fractionally under 2 Gb.
The "expr" command has the same problem.

Your number 11116650496 is just over 10 Gb and too large for Shell arithmetic.

You'll need to use "bc" or "awk" for the arithmetic.

1 Like