4

I want to know how to get the total size of the modified files in the last 30 days.

I have found this command who onlye give me the list of the modified files in the last 30 days.

find . -name '*' -mtime -30

It is useful but I want to know the TOTAL size of this list.

Can someone help getting through this please?

DavidG
  • 113,891
  • 12
  • 217
  • 223
geemeetheway
  • 125
  • 1
  • 10
  • I've flagged to move this question to Super User, the stack exchange site where you're more (most?) likely to get help with this question. – Li-aung Yip Apr 02 '12 at 13:31
  • @Li-aungYip Definitely not. The correct one would be: http://unix.stackexchange.com – Šimon Tóth Apr 02 '12 at 13:35
  • @Let_Me_Be : I prefer Super User - it's more active. But it appears SO has delivered on this question anyway, so no matter. ;) – Li-aung Yip Apr 02 '12 at 13:48
  • `-name '*'` can be removed. It matches all files and since all predicates are anded together, anding with a true predicate is useless. – Jens May 27 '12 at 19:23

3 Answers3

7

Perhaps this would do:

find . -mtime -30 -exec ls -l {} \;| awk '{s+=$5} END {print "Total SIZE: " s}'
John P
  • 15,035
  • 4
  • 48
  • 56
  • None what so ever. Just a copy n paste error from the original statement. I've removed it from the example. Well spotted Jens! – John P May 27 '12 at 20:35
0

You could do this by having find output the size of each file, then total them up with awk

find . -name '*' -mtime -30 -printf '%s\n' | awk '{s+=$1} END {print s}'
Community
  • 1
  • 1
Paul Dixon
  • 295,876
  • 54
  • 310
  • 348
0

Try piping the output of your working find command to du to see if the output its satisfactory. You can use the du switches -c to produce a total, and optionally -h to make it human readable.

eg:

<your command> | du -c

becomes:

find . -name '*' -mtime -30 | du -c 

If you only want the total line:

find . -name '*' -mtime -30 | du -c | grep "total"

Produces output:

360     total

and using du -ch produces:

360K    total
jon
  • 5,986
  • 5
  • 28
  • 35