Categories: Disks and Partitions

du command on Linux (Disk Usage) [Basic Guide]

The du command in Linux (disk usage) will provide a detailed list of disk usage.

It is very useful for determining where the available disk space went, so you can investigate which directory is consuming the disk.

If we don’t pass a directory as a parameter, it uses the current directory as a search base.

The most common options are:

  • -a: Shows all files and not just directories;
  • -c: Shows a total at the bottom of the list;
  • -h: Shows information in a simpler way. Uses the letters M for megabytes and G for gigabytes;
  • -s: Shows a summary of the specified directory and not the total of each subdirectory;
  • -S: Excludes subdirectories from the count;

Examples:

$ du —h /home 2M /home/Carla 4M /home/Cristiane 5M /home/Guilherme 1M /home/michel

With the -sh option, it shows the totalizer, including the subdirectories:

$ du —sh /home 12M /home

With the -Sh option, it shows the totalizer, excluding subdirectories:

$ du —Sh /home 1k /home

If you want to know the total of each subdirectory:

$ du -sh. /*/ 
291M. /carlacru/
173M. /freud/
142M. /mario/
181M. /odonto/
273M. /office/

The –inodes option shows the inode count:

$ du -s --inodes. /*/ 
75. /challenge/
15. /funnel/
2. /music/

You can investigate the entire disk, from the root/:

# du -sh. /*/ 
221M. /bin/
125M. /boot/
0. /dev/
32M. /etc/
12G. /home/
513M. /lib/
219M. /lib64/
0. /media/
0. /mnt/
120K. /opt/
0. /proc/
145M. /root/
420K. /run/
43M. /sbin/
0. /sys/
21M. /tmp/
527M. /usr/
2.8G. /var/

Note that pseudo-file systems such as /proc, /dev, and /sys do not take up disk space because they are actually abstractions of the Kernel and subsystems.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Recent Posts

Sudo command on Linux (privilege scale) [Basic Guide]

The sudo command on Linux executes a given command as if it were another user.…

2 years ago

SS command on Linux (investigate the network) [Basic Guide]

The ss command on Linux is extremely useful for investigating sockets, providing various information about…

2 years ago

Free Linux command (memory usage) [Basic Guide]

Free Linux command shows the amount of total memory in use and available, as well…

2 years ago

Linux while command (loop – while) [Basic Guide]

The shell has structures for testing conditions and executing certain program sequences several times (loop),…

2 years ago

Linux fstab file (disk mount setup) [Basic Guide]

The /etc/fstab file stores the configuration of which devices should be mounted and what is…

2 years ago

Netcat command on Linux (Swiss network knife) [Basic Guide]

The Netcat Command in Linux or nc is a utility used to do “almost anything”…

2 years ago

This website uses cookies.