du Command in Linux
Overview
The du (disk usage) command is a command-line utility that allows you to estimate the space used by files and directories in Linux. This article provides an introduction to the du command, its syntax, options, and example usages.
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
Linux du Command Syntax
The syntax for the du command is as follows:
Where:
- options: Optional flags that alter the behavior of the du command.
- directory: The directory or file to estimate disk usage for.
du Command Options:
- -h: Displays sizes in a human-readable format.
- -s: Displays only the total size of the specified directory.
- -a: Displays the size of all files, not just directories.
- --max-depth: Limits the depth of the directory tree to the specified level.
Example Usages
-
Estimating disk usage of the current directory:
Explanation: Displays the estimated disk usage for the current directory and its subdirectories.
-
Estimating disk usage in human-readable format:
Explanation: Displays the estimated disk usage for the current directory and its subdirectories in a human-readable format (e.g., 1K, 234M, 2G).
Turn Learning into Career Growth
Tips
-
Use 'du -sh' to display only the total size of the specified directory in a human-readable format.
-
Use 'du -ah' to display the size of all files and directories in a human-readable format.
Advanced Use Cases of du Command in Linux
-
Estimating disk usage of a specific directory:
Explanation: Displays the estimated disk usage for the specified directory and its subdirectories.
-
Limiting the depth of the directory tree:
Explanation: Displays the estimated disk usage for the current directory and its immediate subdirectories in a human-readable format.
-
Sorting the output by size:
Explanation: Displays the estimated disk usage for the current directory and its subdirectories in a human-readable format, sorted by size in descending order.
Conclusion
-
The du command is used to estimate the space used by files and directories in Linux.
-
Several options are available to modify the output, such as -h for human-readable format and -s for displaying only the total size.
-
Advanced usages include specifying a directory, limiting the depth of the directory tree, and sorting the output by size.