du
The du ( Disk Usage) command is used to estimate and display the amount of disk space used by files and directories on a Linux system.
It helps users and administrators identify which files or folders consume the most space.
du [options] [directory or filename]
Common Options
Option | Description |
-s | Displays the total disk usage of a specified directory (summary only). |
-h | Shows sizes in a human-readable format (KB, MB, GB, etc.). |
These options are often used together as du -sh to get a quick overview of a folder’s total size.
Example Usages
a. Display the total size of the current directory
du -sh
Shows the total disk usage of the current directory in a readable format.
b. Display the size of a specific file or directory
du -sh filename
Shows the disk usage for the specified file or folder.
c. Display the size of all files and subdirectories
du -sh *
Lists disk usage for each item in the current directory (including files and subfolders).
Additional Notes
du calculates space usage recursively, so it can take time on large directories.
To include hidden files and directories, use:
du -sh .[!.]* *
Combine with sorting to find the largest folders:
du -sh * | sort -hr | head -10
Displays the top 10 largest directories in the current location.
References
Red Hat documentation: du command options