Linux du command
The du
(Disk Usage) command in Linux is used to estimate and display the disk space used by files and directories. It provides a summary of disk usage for a given file or directory, helping users understand how much space is being used on the filesystem.
Basic Syntax:
If no directory is specified, du
will show the disk usage of the current directory.
Commonly Used Options:
-h
: Human-readable format (shows sizes in KB, MB, GB, etc.).-s
: Display only the total for each argument (summarize).-a
: Show disk usage for all files, not just directories.-c
: Produce a grand total (shows total disk usage at the end).-d <depth>
: Limit the depth of directory traversal.-m
: Display disk usage in megabytes.-k
: Display disk usage in kilobytes (this is the default).
Basic Usage:
Example Output:
- The
du
command by default shows the disk usage of each subdirectory in the current directory. - The total disk usage for the current directory (denoted by
.
) is28
blocks.
Example with -h
(Human-readable format):
Sample Output:
- The sizes are now displayed in a human-readable format (KB, MB, GB), making it easier to interpret.
Example with -s
(Summarize):
Sample Output:
- The
-s
option displays the total disk usage of the current directory and its contents, without showing individual subdirectories.
Example with -a
(Show all files):
Sample Output:
- The
-a
option shows the disk usage for all files, not just directories.
Example with -c
(Grand total):
Sample Output:
- The
-c
option produces a grand total of disk usage at the end.
Example with -d <depth>
(Limit depth of directories):
Sample Output:
- The
-d 1
option limits the depth of the directory listing to just one level, showing the disk usage of the directories directly under the current directory.
Example with -m
(Display in Megabytes):
Sample Output:
- The
-m
option displays the disk usage in megabytes.
Example with -k
(Display in Kilobytes):
Sample Output:
- The
-k
option is the default and displays disk usage in kilobytes (KB).
Example with du
on a specific directory:
Sample Output:
- The
-sh
options show the total size of the/path/to/directory
in a human-readable format.
Conclusion:
The du
command is useful for analyzing disk space usage and finding out which files and directories are taking up space. Using the various options such as -h
for human-readable format, -s
for summarizing, and -a
for showing all files, you can customize the output to your needs. It's particularly helpful for system administrators and users trying to manage storage effectively.