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.
To get the total size of a directory in Linux, you can use the du (disk-usage) command. In this article, we'll take a look at some of the most common usages of the du commands, including but not limited to du -sh , du -ch , and du --max-depth .
You can get two kinds of information from the directory: bindings and attributes. The directory can be viewed as consisting of name-to-object bindings. That is, each object in the directory has a corresponding name. You can retrieve an object in the directory by looking up its name.
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>
Use du -sb
:
du -sb DIR
Optionally, add the h
option for more user-friendly output:
du -sbh DIR
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With