# Linux commands: du

> Learn how the Linux du command shows the disk space used by files and directories, with du -h for human-readable sizes and sorting by size using sort -nr.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2020-09-28 | Topics: [CLI](https://flaviocopes.com/tags/cli/) | Canonical: https://flaviocopes.com/linux-command-du/

The `du` command will calculate the size of a directory as a whole:

```bash
du
```

![Terminal showing du command output with size 32 displayed in bytes](https://flaviocopes.com/images/linux-command-du/Screen_Shot_2020-09-04_at_08.11.30.png)

The `32` number here is a value expressed in bytes.

Running `du *` will calculate the size of each file individually:

![Terminal showing du * output listing individual Vue file sizes, each showing 8 bytes](https://flaviocopes.com/images/linux-command-du/Screen_Shot_2020-09-04_at_08.12.35.png)

You can set `du` to display values in MegaBytes using `du -m`, and GigaBytes using `du -g`.

The `-h` option will show a human-readable notation for sizes, adapting to the size:

![Terminal showing du -h output with human-readable sizes in K for various vuehandbook directories](https://flaviocopes.com/images/linux-command-du/Screen_Shot_2020-09-04_at_08.14.40.png)

Adding the `-a` option will print the size of each file in the directories, too:

![Terminal showing du -ah output listing both directories and individual files with their sizes](https://flaviocopes.com/images/linux-command-du/Screen_Shot_2020-09-04_at_08.20.12.png)

A handy thing is to sort the directories by size:

```bash
du -h <directory> | sort -nr
```

and then piping to `head` to only get the first 10 results:

![Terminal showing du -h piped to sort -nr and head, displaying top 10 largest directories by size](https://flaviocopes.com/images/linux-command-du/Screen_Shot_2020-09-04_at_08.22.25.png)

> The `du` command works on Linux, macOS, WSL, and anywhere you have a UNIX environment
