Introduction
In the day to day of a system manager or advanced Linux user, it is essential to know how much space each directory or file occupies. The disk usage command allows quick and flexible measurement of the use of disk space. Unlike df, which shows the space available in the file system, du focuses on the actual consumption of each route.
What is du
Du is a tool included in virtually all Linux distributions. Its main function is to travel a directory tree and add the sizes of the files it contains, presenting the result in blocks or in human-readable units. It is especially useful when you need to identify which folders are consuming more space before cleaning.
Basic syntax
The simplest way to run du is:
du [options] [route]
If a route is not specified, du works on the current directory. By default, it shows the size of each subdirectory in 1024 bytes blocks. To get a more friendly output, it is usually combined with the -h option.
Most useful options
- -h: print the sizes in readable format (K, M, G).
- -s: shows only the total of the specified directory, without disaggregating subfolders.
- -a: includes individual files in addition to directories.
- -c: adds a final line with the total accumulated.
- -max-depth = N: limits the depth of the recursion to N levels.
- -x: remains within the same file system, avoiding crossing assembly points.
Practical examples
To see the legible size of the entire home directory:
du -h ~
If you only want the total summary:
du -sh ~
To list the ten largest directories within / var:
du -h --max-depth = 1 / var | sort -hr | head -10
To include files and get a final total:
du -ahc / usr / local | tail -1
To exclude a file system different from the root:
du -xh /
Tips and tricks
Combine du with other commands such as deaf, head or awk to create custom reports. For example, you can generate a weekly log growth report:
du -h / var / log /* | sort -hr > / tmp / logs _ report.txt
If you work in scripts, use the -b option to get exact byte sizes, which facilitates numerical comparisons.
Remember that du account the space reserved by the file system, so in some cases the number may differ slightly from what df shows due to partially used blocks or the reserve of inodes.
Conclusion
Dominating the du command is essential for anyone who manages Linux systems. Its simplicity and power allow you to quickly detect storage bottle necks and make informed decisions about the cleaning or expansion of the disk. Practice with the options described and adapting them to your needs will make you more efficient in space management.


