I am trying to get the total size of files satisfying a find, e.g.:ls  $(find -maxdepth 2 -type f)However, this kind of invocation of ls does not produce the total size as well.
ls with find :: report total size
bash;find;ls
Believe it or not you can do this with find and du. I used a similar technique that I wrote up on my blog a while a go. That article is titled: [one-liner]: Calculating Disk Space Usage for a List of Files Using du under Linux.The gist of that post is a command such as this:$ find -maxdepth 2 -type f | tr '\n' '\0' | du -ch --files0-from=-ExampleThis will list the size of all the files along with a summary total.$ find -maxdepth 2 -type f | tr '\n' '\0' | du -ch --files0-from=- | tail -100   ./92086/2.txt0   ./92086/5.txt0   ./92086/14.txt0   ./92086/19.txt0   ./92086/18.txt0   ./92086/17.txt4.0K    ./load.bash4.0K    ./100855/plain.txt4.0K    ./100855/tst_ccmds.bash21M totalNOTE: This solution requires that du support the --files0-from= switch which is a GNU switch, to my knowledge.excerpt from du man page--files0-from=F          summarize disk usage of the NUL-terminated file names specified in           file F; If F is - then read names from standard inputAlso this method suffers from not being able to deal with special characters in file names, such as spaces and non-printables.Examplesdu: cannot access `./101415/fileD': No such file or directorydu: cannot access `E': No such file or directoryThese could be dealt with by introducing more tr .. .. commands to substitute them with alternative characters. However there is a better way, if you have access to GNU's find.ImprovementsIf your version of find offers the --print0 switch then you can use this incantation which deals with files that have spaces and/or special characters that aren't printable.$ find -maxdepth 2 -type f -print0 | du -ch --files0-from=- | tail -100   ./92086/2.txt0   ./92086/5.txt0   ./92086/14.txt0   ./92086/19.txt0   ./92086/18.txt0   ./92086/17.txt4.0K    ./load.bash4.0K    ./100855/plain.txt4.0K    ./100855/tst_ccmds.bash21M total