Find the total size of multiple files

If I have a number of files in a directory, for example,
test.1
test.2
test.3
abc.1
abc.2
abc.3

and I need to find the total file size of all of the test.* files, I can use du -bc test.* in Linux.

However, in Solaris, du does not have the -c option. What can I do in Solaris to get the total size? Thanks.

You can use

du -sh *

This will give all the files and directories in the directory you are in.

du -sh test*

Will give you all files and directories that start with test.
Is this what your looking for.

Search the forum before you post
http://www.unix.com/unix-dummies-questions-answers/149637-get-total-size-files.html

Unless I missed it, there's nothing in that thread that's equivalent to du -bc . GNU du's -b option reports file size, not disk space allocated.

Regards,
Alister

Thanks for the responses. The awk command solves the problem:

ls -l test.* | awk '{t+=$5}END{print t}'

, where 5 is the column number in "ls -l" output for displaying file size.

du -sh test.* only provides the size of each file, but not the sum of them.

du doesn't provide file length anyway, it measures disk used at the sector level.

The du command in post #1 actually does measure file length.

Regards,
Alister

cat test.* | wc -c

cat in unnecessary, pipeline can be avoided.

Also please note wc -c is going to be really slower if we are gonna deal with huge files. So I think using ls is a better option.

Not necessarily: wc -c test* will print all sizes with file name, and a total trailer. cat | wc will count chars from stdin and print just the total.

Try - should stat and shell arithmetics be available - this:

$ printf "%d\n" $(( $(stat --printf="%s+" test*)0 ))

Must agree, this is not a UUOC, this is precisely what cat was meant for, concatenating files.

I agree if the requester want just the total.

But reading his/her original request I think he/she is interested in an output similar to du -bc in Linux

$ du -bc file*
10      file1
10      file2
10      file3
30      total

Similar output can be produced using wc -c without piping input from cat command:

$ wc -c file*
10 file1
10 file2
10 file3
30 total