What does the '--max-depth' option do in the 'du' command?

0920

The --max-depth option in the du (disk usage) command is used to limit the depth of the directory tree that du will traverse when calculating disk usage. This is particularly useful when you want to focus on a specific level of the directory hierarchy without getting overwhelmed by too much detail.

How It Works

  • --max-depth=N: This option specifies the maximum depth of directories to display. The depth is counted from the starting directory you specify.

Examples

  1. --max-depth=0: This will show only the total size of the current directory, without including any subdirectories.

    du -h --max-depth=0
  2. --max-depth=1: This will show the sizes of the current directory and its immediate subdirectories.

    du -h --max-depth=1

Example Output

Assuming you are in a directory with the following structure:

/project
├── logs
│   ├── application
│   └── system
└── data
  • Running du -h --max-depth=0 might output:

    10M .
  • Running du -h --max-depth=1 might output:

    5M ./logs
    5M ./data
    10M .

Why Use --max-depth?

Using --max-depth helps you quickly identify which directories are consuming the most space without having to sift through every single subdirectory. This is especially useful in large directory structures where you want to manage disk space efficiently.

If you have any more questions or need further clarification, feel free to ask!

0 Comments

no data
Be the first to share your comment!