Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use du to take the paths from stdin and calculate the total size? [duplicate]

Tags:

linux

shell

unix

Possible Duplicate:
Get total size of folders with find & du

I can use du like this to get the file size of each file from stdin

find . -name "*.java" -exec du -h {} \;

But I can't get the total size.. Does anyone have ideas about that? Thanks!

like image 289
Hanfei Sun Avatar asked Feb 18 '23 18:02

Hanfei Sun


1 Answers

Answered here:

How to get total size of folders with find and du?

Use xargs(1) instead of -exec:

find . -name bak -type d | xargs du -ch

executes the command for each file found (check the find(1) documentation). Piping to xargs lets you aggregate those filenames and only run du once.

In your case it would be:

find . -name "*.java" | xargs du -ch

Options:

   -c, --total
          produce a grand total
like image 180
jingtao Avatar answered Feb 27 '23 10:02

jingtao