views:

377

answers:

4

For instance, I have a large filesystem that is filling up faster than I expected. So I look for what's being added:

find /rapidly_shrinking_drive/ -type f -mtime -1 -ls | less

And I find, well, lots of stuff. Thousands of files of six-seven types. I can single out a type and count them:

find /rapidly_shrinking_drive/ -name "*offender1*" -mtime -1 -ls | wc -l

but what I'd really like is to be able to get the total size on disk of these files:

find /rapidly_shrinking_drive/ -name "*offender1*" -mtime -1 | howmuchspace

I'm open to a Perl one-liner for this, if someone's got one, but I'm not going to use any solution that involves a multi-line script, or File::Find.

+2  A: 

The command du tells you about disk usage. Example usage for your specific case:

find rapidly_shrinking_drive/ -name "offender1" -mtime -1 -print0 | du --files0-from=- -hc | tail -n1

(Previously I wrote du -hs, but on my machine that appears to disregard find's input and instead summarises the size of the cwd.)

Stephan202
Very nice. Although, remembering that brutal keyword to 'find' ("--files0-from=") may not actually be easier than remembering the 'awk' sequence.
Ed Hyer
+1  A: 

Darn, Stephan202 is right. I didn't think about du -s (summarize), so instead I used awk:

find rapidly_shrinking_drive/ -name "offender1" -mtime -1 | du | awk '{total+=$1} END{print total}'

I like the other answer better though, and it's almost certainly more efficient.

pix0r
A: 

You could also use ls -l to find their size, then awk to extract the size:

find /rapidly_shrinking_drive/ -name "offender1" -mtime -1 | ls -l | awk '{print $5}' | sum
Sinan Taifour
that's wrong. ls -l is not needed.
ghostdog74
A: 

with GNU find,

 find /path -name "offender" -printf "%s\n" | awk '{t+=$1}END{print t}'
ghostdog74