# du

## Introduction

`du` is a command in linux (short for disk usage) which helps you identify what files/directories are consuming how much space.

***

## Syntax

`du [OPTION]... [FILE]...`

`du [OPTION]... --files0-from=F`

***

## Important Flags

<table><thead><tr><th width="291">Flag</th><th>Description</th></tr></thead><tbody><tr><td><code>-0, --null</code></td><td>End each output line with NULL</td></tr><tr><td><code>-a or --all</code></td><td>Displays disk usage information for all files and directories, including hidden ones.</td></tr><tr><td><code>--apparent-size</code></td><td>Print apparent sizes, rather than disk usage</td></tr><tr><td><code>-B, --block-size=SIZE</code></td><td>Scale sizes to SIZE before printing on console</td></tr><tr><td><code>-c or --total</code></td><td>Shows the total disk usage in addition to individual usage for directories and files.</td></tr><tr><td><code>-d, --max-depth=N</code></td><td>Print total for directory only if it is N or fewer levels below command line argument</td></tr><tr><td><code>-h or --human-readable</code></td><td>Displays sizes in human-readable format, using units such as KB, MB, GB, etc. This option makes it easier to interpret the disk usage information.</td></tr><tr><td><code>-S, -separate-dirs</code></td><td>For directories, don’t include size of subdirectories</td></tr><tr><td><code>-s or --summarize</code></td><td>Provides a summary of the disk usage for the specified directory or file, without displaying individual usage details for subdirectories.</td></tr><tr><td><code>--time</code></td><td>Show time of last modification of any file or directory</td></tr><tr><td><code>--exclude</code></td><td>Excludes specific directories or files from disk usage calculation based on patterns or names.</td></tr></tbody></table>

***

## Examples

<table><thead><tr><th>Command</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">du -a /home
</code></pre></td><td>To display the disk usage information for all files and directories, including hidden ones in the home directory.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">du -h /home
</code></pre></td><td>You can print sizes in human-readable format (e.g., 1K 234M 2G), using the `-h` option.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">du -a -h /home
</code></pre></td><td>Combine `-a` and `-h` flags together to check all files and folder sizes.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">du -c -h /home
</code></pre></td><td>Use -c option to print total size</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">du -d 1 /home
</code></pre></td><td>To print sizes to particular level, use -d option with level no.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">du -d 2 /home
</code></pre></td><td>Now try with level 2, you will get some extra directories</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">du -s /home
</code></pre></td><td>Get summary of file system using -s option</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">du -sh --apparent-size /home
</code></pre></td><td>Print apparent sizes, rather than disk usage; although the apparent size is usually smaller, it may be larger due to holes in (‘sparse’) files, internal fragmentation, indirect blocks, and the like.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">du --time -h /home
</code></pre></td><td>Get the timestamp of last modified using --time option</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">du --time -d 1 /home/
</code></pre></td><td>Check the timestamp of the last modification of files and directories to 1 level.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">du --max-depth=1 /path
</code></pre></td><td>To find the largest directories, you can use the du command with the --max-depth option.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">du -h /path
</code></pre></td><td>The du command supports the -h option to display sizes in a human-readable format (e.g., KB, MB, GB).</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">find /path -type f -exec du -h {} + | sort -rh | head -n 10
</code></pre></td><td>You can combine the find command with du to identify large files.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">du -h --exclude=/path/to/exclude /path
</code></pre></td><td>To exclude specific directories, use the --exclude option with the du command.</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://thamizhiniyancs.gitbook.io/cheatsheets/linux/surfing-knowing-your-file-system/du.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
