Total size of the contents of all the files in a directory

Arthur Ulfeldt picture Arthur Ulfeldt · Aug 7, 2009 · Viewed 134.5k times · Source

When I use ls or du, I get the amount of disk space each file is occupying.

I need the sum total of all the data in files and subdirectories I would get if I opened each file and counted the bytes. Bonus points if I can get this without opening each file and counting.

Answer

Arkady picture Arkady · Aug 7, 2009

If you want the 'apparent size' (that is the number of bytes in each file), not size taken up by files on the disk, use the -b or --bytes option (if you got a Linux system with GNU coreutils):

% du -sbh <directory>