du Command - Check Directory Capacity

You can check the directory capacity with the du command. If no directory name is specified, the current directory will be the target.

du DirectoryName

This is a sample to check the directory capacity with du.

du templates

This is a sample output result.

468     templates/blog
8       templates/static/images
12      templates/static/css
4       templates/static/blog
192     templates/static/js/google-code-prettify
292     templates/static/js
324     templates/static
28      templates/common
828     templates

The capacity is displayed in kilobytes for each directory and subdirectory.

To display in an easy-to-understand manner with units

Use the "-h" option to clearly display the units of the du command.

du -h

The output result has a unit.

Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           794M  736K  793M   1% /run
/dev/sda1        29G  4.1G   25G  15% /
tmpfs           3.9G  8.0K  3.9G   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda15      105M  3.6M  101M   4% /boot/efi
/dev/sdc1      1007G   77M  956G   1% /datadrive
/dev/sdb1        16G   45M   15G   1% /mnt
tmpfs           794M     0  794M   0% /run/user/1001

Arrange directory usage from top to bottom

To display the directory usage in order from the top, combine sort and head with the du command. Useful for discovering large directories.

du templates | sort -rn | head -20

The output results are output in descending order of directory capacity.

824     templates
464     templates/blog
324     templates/static
292     templates/static/js
192     templates/static/js/google-code-prettify
28      templates/common
12      templates/static/css
8       templates/static/images
4       templates/static/blog

Specifying "/" for du and waiting for a while is convenient because you can see which directories are consuming space on the entire system.

How to check the capacity of the disk?

Use the df command to check the capacity of the disk.

Note that the du command is a command to check the directory capacity, and the df command is used to check the disk capacity.

Associated Information