Disk Management

du Command on Linux

Every Linux distro comes up with a number of tools integrated into the system. Each of the tools has their own purposes. “du” is such a tool that’s part of the standard Unix/Linux. This tool is used for getting info on disk usage and directories on machines. There are a number of available parameters that you can use for getting results in many formats. Here are some of the most useful commands of “du”.

“du” examples

  • Need to find out the disk usage summary of a directory? Run the following command –
  • du ~/Downloads/

In the output, the first column is the disk usage amount and the second column is the list of files present in that directory.

The first column shows the number of disk blocks the corresponding file is occupying.

  • Need the output in a format that human can understand? Use the “-h” option. It tells the “du” to show output in “Human Readable Format”.
  • du -h ~/Downloads

  • Use “-a” flag for displaying the disk usage of all the files and directories.
  • du -a -h ~/Downloads/

As you’ve noticed, you can use multiple flags together with “du”.

  • For identifying just how much disk space is a directory consuming, use “-s” flag.
  • du -sh ~/Downloads

  • You can also use the “-c” flag for getting the total size of the directory at the last line of the output.
  • du -ch ~/Downloads/

  • Need to check out the last time of file modification? You have to use “–time” flag.
  • du -ha --time ~/Downloads/

  • Are you interested in excluding specific file types, for example, MP4 or PDF? Then use the “–exclude=PATTERN” parameter.
  • du -ha --exclude=*.svg ~/Downloads/

More “du” commands

“du” offers a huge collection of features. You can find out all of them using the man page for “du”.

man du

Every time you need help, you don’t have to open up a terminal and run the command again. You can dump the guide into a text file. Run the following command –

man du > ~/Desktop/du.txt

Enjoy!

About the author

Sidratul Muntaha

Sidratul Muntaha

Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.