How can I get the size of all files and all files in its subdirectories using the du command.

I am trying the following command to get the size of all files (and files in subdirectories)

find . -type f | du -a

But this prints out the folder sizes as well. How can I get a listing of sizes of all files and files in subdirectories? I also tried the exec flag but I am not sure how to pipe the output into another command after it executes the results of find into du.

Sorry should have mentioned this before, the operating system is AIX 6.1 with ksh shell.

I'd go with this answer if you don't have access to find -print0 or other GNU features. If available, replacing \; with \+ will result in fewer invocations of du and thus better performance.
–
jw013Oct 11 '11 at 22:02

The command is failing saying print0 is not a valid command and that last minus was not a recognized flag. I don't think this approach will work because man du doesn't list a files or from flag.
–
Shardul UpadhyayOct 11 '11 at 20:00

You should add your operating system as a tag to the question. I assumed you had GNU but forgot to mention that.
–
jw013Oct 11 '11 at 20:04

Xargs usually calls the command, even if there are no arguments passed; xargs du </dev/null will still be called, xargs -r du </dev/null will not call du. The -0 argument looks for null-terminated strings instead of newline terminated.

Then I usually add | awk '{sum+=$1} END {print sum}' on the end to get the total.