The du command in Linux and Unix-like systems is used to estimate the disk space usage of a file or directory. It recursively walks through the directory tree and displays the size of each file and directory, including the total space consumed by the directory and its subdirectories.
Here is the basic syntax for the du command:
du [options] [directory]
directory is the name of the directory for which you want to estimate disk space usage. Here are some examples of the du command:
1. To estimate the disk space usage of the current directory
$ du
2. To estimate the disk space usage of a specific directory
$ du /path/to/directory
3. To estimate the disk space usage of a specific file
$ du /path/to/file
4. To display the disk space usage in human-readable format
$ du -h
Note: The -h option is used to display the disk space usage in human-readable format.
5. To display the disk space usage of a specific directory, including subdirectories
$ du -a /path/to/directory
Note: The -a option is used to display the disk space usage of all files, including subdirectories
6. To display the disk space usage of all directories in the current directory
$ du -d 1 .
Note: The -d option is used to specify the depth of the directory tree to display and the number following it specify the depth.
The du command is useful for estimating the disk space usage of a file or directory, it recursively walks through the directory tree and displays the size of each file and directory, including the total space consumed by the directory and its subdirectories. This command is useful to identify the directories that are consuming a large amount of disk space and take appropriate action to free up space. Additionally, the du command can be used in conjunction with other commands like df to further investigate the disk space usage of the entire file system.