The du Command and Its Options
The du
(disk usage) command in Linux is a powerful tool used to analyze and display the disk space usage of files and directories. It provides valuable information about the size of individual files, directories, and the overall disk usage on a system. The du
command offers several options that allow you to customize its behavior and obtain the desired information.
Common du Command Options
Here are some of the most commonly used du
command options:
- -a or --all: This option displays the disk usage for all files, including hidden files and directories.
- -h or --human-readable: This option displays the disk usage in a human-readable format, such as kilobytes (kB), megabytes (MB), or gigabytes (GB), instead of bytes.
- -s or --summarize: This option displays the total disk usage for the specified directory or file, instead of the individual file or directory sizes.
- -c or --total: This option displays the grand total of the disk usage for all the specified files and directories.
- -d or --max-depth=: This option limits the depth of the directory tree that
du
will traverse, where<depth>
is the maximum number of levels to display. - -x or --one-file-system: This option restricts
du
to only display the disk usage for the current file system, and excludes any mounted file systems. - -L <link_name> or --dereference <link_name>: This option follows symbolic links and displays the disk usage of the linked files or directories, instead of the links themselves.
- -t or --threshold=: This option displays only the files and directories that exceed the specified size threshold.
Mermaid Diagram: du Command Options
Examples
-
Displaying the disk usage of the current directory and its subdirectories in a human-readable format:
du -h
-
Displaying the total disk usage of the current directory:
du -s
-
Displaying the disk usage of the current directory and its subdirectories up to a depth of 2 levels:
du -d 2
-
Displaying the disk usage of the current directory and its subdirectories, excluding any mounted file systems:
du -x
-
Displaying the disk usage of symbolic links, following the linked files or directories:
du -L
The du
command is a versatile tool that can help you better understand and manage the disk space usage on your Linux system. By using the various options, you can tailor the command's output to suit your specific needs and gain valuable insights into your file system.