Linux BASH: Finding files and then getting sum of those files?

Namuna

Platinum Member
Jun 20, 2000
2,435
1
0
Goal:
Find log files, in a specific directory, generated in a 24hr period (could be THOUSANDS), then sum up the size of the result so as to know how much space is being used in a given 24hr period.

Commands tried so far:
- 'find ./ -type f -mtime -1 -exec du -sch'
The 'du' command is tallying up EACH file, instead of the whole result
- 'find ./ -type f -mtime -1 | xargs du -sch'
This gives a false result because xargs breaks the results (from find) into chunks of lines so as to not exceed the buffer limit, which throws off the du command

Suggestions/Help is much appreciated!

Thanks.
 

bersl2

Golden Member
Aug 2, 2004
1,617
0
0
Try this:

find . [whatever conditions] -exec du -s '{}' \; > sumfile
cut -f1 sumfile > sumfile2
(( i=1 )); (( count=`wc -l sumfile2 | cut -d' ' -f1` - 1 )); while (( i <= count )); do
echo + >> sumfile2
(( ++i ))
done
echo p >> sumfile2
dc -f sumfile2

It's probably easier to write a small C program though.
 

Namuna

Platinum Member
Jun 20, 2000
2,435
1
0
thanks for the responses guys...I actually found a way to get the job done using something like this:

TOTAL_SIZE=0
for i in `find . -type f -mtime -1 | xargs du -sc | grep total | awk '{print $1}'
do
TOTAL_SIZE=`expr $TOTAL_SIZE + $i`
done
echo $TOTAL_SIZE