du Command in Linux

Learn via video courses
Topics Covered

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

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

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

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

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.

Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more