du
du
The du command in Unix-like operating systems is used to estimate file and directory space usage. It stands for "disk usage". Here’s an overview of du and its common usage:
Overview of du
duPurpose: du is used to determine the disk usage of files and directories within a filesystem. It recursively traverses directories and reports back the total disk space used by each file and directory.
Availability: du is a standard command-line utility available on Unix-like systems, including Linux distributions, macOS, and BSD variants.
Common du Commands and Usage
du Commands and UsageDisplay Disk Usage of Current Directory:
To display the disk usage of files and directories in the current directory:
duBy default,
durecursively lists the disk usage of all files and directories starting from the current directory.
Display Disk Usage of a Specific Directory:
To display the disk usage of a specific directory (e.g.,
/home/user/docs):du /home/user/docsReplace
/home/user/docswith the path to the directory you want to analyze.
Display Human-Readable Format:
To display disk usage in a more human-readable format (e.g., in kilobytes, megabytes, gigabytes):
du -hThe
-hoption (or--human-readable) converts sizes into a human-readable format.
Display Total Disk Usage:
To display the total disk usage of a directory, including all its subdirectories:
du -h --summarize /path/to/directoryThe
--summarizeoption provides a summary at the end of the output, showing the total disk usage.
Sort Output by Size:
To sort the output of
duby size, showing the largest items first:du -h | sort -rhThe
-roption sorts in reverse order (largest to smallest), and-hprovides human-readable sizes.
Limit Depth of Recursive Search:
To limit the depth of recursive directory search (e.g., up to 2 levels):
du -h --max-depth=2 /path/to/directoryAdjust
2to the desired depth level you want to analyze.
Considerations
Symbolic Links: By default,
dudoes not follow symbolic links unless specified with the-Loption.Permissions: Ensure the user running
duhas appropriate permissions to access the directories and files being analyzed.Performance Impact: Analyzing large filesystems with
ducan be resource-intensive, especially when used with options like-rfor recursive scanning.
Alternatives
ncdu: A text-based disk usage analyzer that provides an interactive interface for exploring disk usage and navigating directories.
Disk Usage Analyzers: Graphical tools like
Baobab(for GNOME) andFilelight(for KDE) offer visual representations of disk usage.
Conclusion
du is a versatile command-line tool for analyzing disk usage on Unix-like systems, providing insights into file and directory sizes within filesystems. It’s useful for managing disk space, identifying large files, and optimizing storage resources.
help
Last updated