I have a file with a list of files and directories, containing the wildcard *
. I am trying to output the size of the entries with du
and would like a grand total.
If I start with:
cat file | xargs du -hs
the wildcard *
is not expanded. To do so, I do:
cat file | xargs -I@ sh -c 'du -hs @'
But if I try:
cat file | xargs -I@ sh -c 'du -hsc @'
I get a total for each (expanded) entry of the file. If the file looks like:
foo*
bar*
I will get:
1K foo1
1K foo2
2K total
1K bar1
1K bar2
2K total
How do I get the grand total of all entries in the file? How do I run du
only once for all the lines? Thanks