in

LinuxLinux GeekGeek

DU Command in Linux- How to Use DU on Linux Ubuntu 18.04 LTS/ 19.10

How to use Disk Usage Command in Linux Ubuntu, and Ubuntu-based Distros

DU Command in Linux

D

U Command in Linux Ubuntu: DU command provides the information on Disk Usage of Files and Directories on Linux Ubuntu, and Ubuntu-based Distros. On Windows, We will get to know about the Disk Usage(in percentage) from the Task Manager. The main advantage of DU on Ubuntu is that you can check the individual files or directories disk usage thereby giving us precise data. In this article, we will check out everything about the usage of DU Command in Linux Ubuntu 18.04 LTS(Bionic Beaver), Ubuntu 19.10(Eoan Ermine), and other Ubuntu-based distros with clear examples.

Jump to:

Du Command Usage with flags and options:

Basic App Details & Requirements

DU Command FlagsUsage
-hDisplay the Disk Usage value in Human-Readable Format
-cDisplay the Grand Total of a Directory
-kDisplay the Disk Usage value in Kilobyte
-mDisplay the Disk Usage value in Megabyte
-b Display the Disk Usage value in Byte
-sOnly Provides the Summarised Disk Usage of a Directory
-0Ends each output with null and no newline(Output will not be clear)
-aProvide individual file’s disk usage of a directory
--timeDisplay Disk Usage of file or folder along with its Date and Time of modification
--siDisplay values based on Binary Conversion(1000 and not 1024)
--helpDisplay the Help menu of DU Command
--versionDU Version check-up
--excludeExclude files that match Patterns and then Display it
--threshold=SIZEDisplay the files that meet the minimum threshold size that we had specified, specify the size in kilobytes

Beginners Bay:

How to Use DU Command on Linux Ubuntu 18.04 LTS/ 19.10- Clear Examples:

We have explained all the important DU Command’s usage with Examples and Images. If you find any difficulty following it up, please let us know in the comment section and we will try to solve it.

Check this too  How to Get Name, Type & Vendor of Connected USB in Ubuntu 18.04 & 19.10?

DU Command- General Syntax:

du [options] [file]

du [options] [Directory]

du [OPTION]... --files0-from=F

Example 1- (Directory’s Disk Usage Check with DU Command):

Consider the following situation. Let us create a directory(folder) named “tecrobust” on your Home directory. Now, let us check the Disk Usage of the directory “tecrobust” with the help of du command. Refer to the following image for the realtime result.

By default, the values are in Kilobytes(KB). Don’t worry, in the next section, we will check out how to display the values in MB and GB(Human readable format).
du ~/tecrobust
Du Command usage for Directory
Du Command usage for Directory
Note: Instead of using the full path of a file on the Home directory, you can just use which the system will understand as /home/username/.

Example 2- (File’s Disk Usage Check with DU Command):

In this example, let us check the file disk usage. Instead of creating it on the Home directory, we will create it on the Desktop and name it as “tr”. Let us create a text file under the name “notes”. We are all set. It is time to check out the real-time output.

Open Terminal and change directory to Desktop using cd Desktop.

du ./tr/notes
du command usuage for file
du command usage for file
Note: Dot symbol(.) represents the present directory. Hence, instead of typing the path with Desktop/…../…., you can just use the Dot symbol(.) as mentioned above that will tell the system that it represents the present directory.

How to Display Disk Usage of files and directories in Human Readable Format(flag -h):

General Syntax:

du -h [file]

du -h [directory]

Example- (File/Folder Disk Usage in Human Readable Format using DU Command):

I have created a directory under the name “videos” that contains a number of video files. Let us check the Disk Usage of this directory in a human-readable format.

du -h /home/tec/videos
Disk Usage of a Directofy in Human Readable Format
Disk Usage of a Directory in Human Readable Format
On the above output, the “G” represents Gigabyte(GB). Likewise, “K” will represent Kilobyte(KB), “M” will represent Megabyte(MB), and more.

How to Display Disk Usage Values in Bytes, KB, and MB(flag -k & flag -m):

General Syntax:

du -k [file]                      (For Byte)

Check this too  Virtual Machine for Ubuntu- How to Install Virtual Box and use Ubuntu 18.04 LTS on It

du -k [file]                    (For Kilobyte)

du -m [file]                   (For Megabyte)

Example- (Folder Disk Usage in KB and MB)

Let us check the disk usage of the directory “videos” that I have created on the Home Directory in Kilobyte and Megabyte.

du -k /home/tec/videos
Disk Usage Value in KB
Disk Usage Value in KB
du -m /home/tec/videos
Disk Usage Value in MB
Disk Usage Value in MB

How to Display the Total Disk Usage Value of a Directory(flag -c):

On the first method, we saw how to check the file and directory disk usage with the DU command. However, with that method, we will not get the sum total disk usage value of the specified directory rather it will just list out all the files usage value of that directory. Let us sum up totally how much a directory’s total disk usage.

General Syntax:

du -c [folder]

Example- Grand Total Disk Usage value of a Directory:

I have a directory named snap on the Home directory that contains all the information of snap apps installed. Let us check the total disk usage of that folder.

du -c /home/tec/snap

After executing the above command on the terminal, the output as follows.

Grand Total of a Directory
Grand Total of a Directory

How to use two Flags with DU Command:

We are aware of using flags(options) with DU command from the above examples. Here, we will see how to use two flags in a single DU Command.

General Syntax:

du -flag1flag2 [file]

Eg: du -ch [file]

Example- Check the Grand total(-c) of a Directory and display them in a human-readable format(-h):

Let us check the same Snap directory’s disk usage grand total and list the values in a human-readable format.

du -ch /home/tec/snap
Input(Two flags in a du command)
Input(Two flags in a du command)
Using two flags on du command
Output(Two flags on du command)

How to Display Disk Usage with Date and Time of Modification of a file or folder(flag --time):

We will use the flag --time to display the disk usage of a specified file or folder along with its time and date of the Modification.

General Syntax:

du --time [file]

du --time [folder]

Example- Display Disk Usage of files/folders along with Time and Date of Modification:

We will use the same directory snap that is created on the Home directory by the snap applications.

du --time /home/tec/snap
Input(Using time flag in du command)
Input(Using --time flag in du command)
Output(Displays Disk Usage along with Time and Date)
Output(Displays Disk Usage along with Time and Date)

How to use 3 different flags in DU Command(
flag --flag):

In general, we know that a flag with one string will be accompanied by a single semicolon(-) and a flag with more than one string will be accompanied by a double semicolon(–). Here, we will see how to use both of these flags in du command.

Check this too  Fix- Could not get lock /var/lib/dpkg/lock-frontend on Linux 18.04 LTS/ 19.10

General Syntax:

du -flag1 --flag2 [file]

du -flag1flag2 --flag3 [file]

Example- Display a Folder’s Disk Usage along with Grand Total Usage in a Human-readable format along with its Date & Time of Creation:

The same directory “Snap” that has been created on the Home directory will be used for this explanation. As told, let us display the grand total usage of this directory in a human-readable format and also specify the date and time of the creation of the files of the snap directory.

du -ch --time /home/tec/snap
Input
Input
Output(Using three flags on du command)
Output(Using three flags on du command- Human Readable, Grand Total, and Date & Time of Creation)

Display the Summarized Disk Usage of a Directory(flag -s):

Sometimes, we may just need the summarized disk usage of a folder or directory. If we wish to exclude all the files of the directory’s disk usage while using the du command, then follow the below syntax.

General Syntax:

du -s [folder]

Example- Let us summarize the Disk Usage of the Directory without listing all its file’s information:

We will use the same “Snap” Directory of the Home directory. Refer to the following example

du -s /home/tec/snap
Summarise a Directory's Disk Usage
Summarise a Directory’s Disk Usage

How to get the Help menu of DU Command:

Use the following command on the terminal to get the help menu of the du command.

$du --help
DU Command Help menu
DU Command Help menu

How to check out the DU Version:

$du --version
du version
du version

Get in Touch with us:

The above article provides detailed information about Disk Usage Command(DU) and provides various examples with clear images and scenarios that will help beginners to understand the concepts clearly and people with experience can just pick their required command usage from the table.

If you have any queries with the above article, let us know in the comment section. For instant solutions, Kindly visit our Forum!!

 

Article Review
  • Article Quality
  • Content Depth
  • Explanation
  • Article Efficiency
4.8

Summary

For more interesting articles, Visit our Homepage

Leave a Reply

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

Written by Mike

Seeker of nature. For me, everything is about nature. Loves to gaze through different scapes, weather and admire the colors of nature. Contact me through the Contact Us adding "@Mike" on the Subject box.

nmcli command in Linux

NMCLI Command To Show Available WiFi Networks, Signal Strength on Linux!

Polo File Manager for Ubuntu

Polo File Manager Ubuntu- Install Polo on Linux Ubuntu 18.04 LTS/ 19.10