Skip to content

du command on Linux (Disk Usage)

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. /*/ <br></br>291M. /carlacru/ <br></br>173M. /freud/ <br></br>142M. /mario/ <br></br>181M. /odonto/ <br></br>273M. /office/

The —inodes option shows the inode count:

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

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

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