How to Show Disk Usage in Linux With the du Command

If your PC is running slow or you're having issues installing updates and software, there's a high chance you might be running out of disk space. The handy du command makes it convenient for Linux users to stay aware of their disk consumption and make an upgrade if required.

But how exactly do you issue this command on Linux? Let us find out.

Prerequisites

To be able to use the du command, you need to have the following:

  • A Linux-based system
  • A Linux terminal or command line
  • A user account with sudo or root privileges

Note: Sudo in Linux stands for “superuser do”. A superuser has the highest level of permission and can execute any administrative commands.

Related: How to Add a User to the Sudoers List in Linux

How to Use the du Command

The du command displays disk usage. Using it without any options will recursively check every folder and subfolders in the current working directory. To utilize the basic usage of the du command, simply open a terminal window, type du, and hit Enter.

du

Output:

The output displays each directory's disk usage and path, along with the total disk usage of the parent directory. Besides the du command, Linux also comes equipped with several other disk analyzers such as gdu that can output disk usage for you.

A Few du Command Options

The usefulness of this command can be easily expanded by using various options. Here are some basic flags that you can use with du:

Display Output in Human Readable Format

By default, the output generated by Linux commands is not very user-friendly and it is difficult to make out the size of the disk by looking at the output. To make the command human-readable, type du -h and hit Enter.

du -h

Get the Summary of the Directory Size

The du command outputs a lot of file-related information that can be confusing when all you are trying to find out is the total size of your directory. To display the total size of a directory, use the -s flag with the command. The -s flag stands for Summarize.

du -s

Display Directory Size in Kilobytes (KB) or Megabytes (MB)

You also have the option to display disk usage size in either KB or MB. To achieve this, simply use the -k flag for Kilobytes, and the -m flag for Megabytes.

du -k
du -m

Display Disk Usage After System Modification

To display disk usage after a modification has taken place on your Linux system, use the –time flag with the default command.

du --time

Output:

Related: How to Check Your Laptop's Battery Health in Linux

Monitoring Disk Usage on Linux

Du is a versatile command for Linux users as it comes with a myriad of options. If keeping track of disk usage is important to you then the du command should be on top of your arsenal of Linux commands.

Linux allows the superuser to grant administrative access to any user at any time. You can even change the username and other account details associated with a user account on Linux.

Author: Kinza Yasar

Source: Kinza Yasar.” How to Show Disk Usage in Linux With the du Command”. Retrieved From https://www.makeuseof.com/du-command/

All Rights Of This Article Reserved To MakeUseOf

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: