9 du Commands in Linux to Check Disk Usage (With Practical Examples)


Learn how to use the du command in Linux to check disk usage, find large files and directories, and free space using practical, real-world command examples.

It is a standard command used to estimate space usage (meaning, in the terminal we can find the exact size each directory and file takes up). There are multiple ways we can generate various types of output in Terminal using the 'du' command with various options. It is usually used by all System Administrators to find unwanted files, files with unused large sizes, or archive files that can be deleted/cleared in order to provide sufficient free space for servers.

In addition to the du command, System Administrators will also use the df command to monitor the space occupied in the servers and storage boxes, to learn more information about the 'df' command,
click here.

Users without permission cannot execute the 'du' command on a specific file or directory. In those cases, you will need to use the 'sudo' command. Setting up sudo users?
Click here to find the steps.

This guide will help you on how to use various options with du commands. All the below examples were tested on RHEL/CENTOS 7.6.

The Global Syntax of using du Command to Check Disk Usage in Linux:

du [OPTION]... [FILE]...
du [OPTION]... --files0-from=F
1. How to check the disk usage summary of a directory?
# du linuxteck

Output:
984        linuxteck/.svn/pristine/16
2936       linuxteck/.svn/pristine/f3
32948      linuxteck/.svn/pristine/7b
5676       linuxteck/.svn/pristine/a7
26604      linuxteck/.svn/pristine/80
2460       linuxteck/.svn/pristine/ca
2964       linuxteck/.svn/pristine/09
1429536    linuxteck/.svn/pristine
1439820    linuxteck/.svn
2920440    linuxteck

Note: The 'du' command without any options will list all the files and folders in the given directory or the current working directory.

2. How to check disk usage in a human-readable format?
# du -h linuxteck

Output:
984K      linuxteck/.svn/pristine/16
2.9M      linuxteck/.svn/pristine/f3
33M       linuxteck/.svn/pristine/7b
5.6M      linuxteck/.svn/pristine/a7
26M       linuxteck/.svn/pristine/80
2.5M      linuxteck/.svn/pristine/ca
2.9M      linuxteck/.svn/pristine/09
1.4G      linuxteck/.svn/pristine
1.4G      linuxteck/.svn
2.8G      linuxteck
3. How to check the total usage size of a particular directory?
# du -sh linuxteck

Output:
2.8G linuxteck
4. How to list the disk usage of all files including directories?
# du -a linuxteck

Partial Output:
12   linuxteck/.svn/pristine/09/09f1e40157be7ffd978ca54e7b0008f4fa295d4d.svn-base
4    linuxteck/.svn/pristine/09/092262196b9dedac2bfe0ecfcef1351fdf502d06.svn-base
980  linuxteck/.svn/pristine/09/09545e437a50988578e1204eab3cdd6db16bfb4b.svn-base
20   linuxteck/.svn/pristine/09/09e0967731aece14f71707f6af7dff96f84ad17a.svn-base
2964 linuxteck/.svn/pristine/09
1429536 linuxteck/.svn/pristine
10268 linuxteck/.svn/wc.db
1439820 linuxteck/.svn
4    linuxteck/wp-register.php
2920440 linuxteck
5. How to print the grand total for a directory?
# du -ch linuxteck

Output:
3.1M      linuxteck/.svn/pristine/c6
2.2M      linuxteck/.svn/pristine/3c
2.0M      linuxteck/.svn/pristine/77
3.2M      linuxteck/.svn/pristine/81
2.5M      linuxteck/.svn/pristine/f6
1.4G      linuxteck/.svn/pristine
4.0K      linuxteck/.svn/tmp
1.4G      linuxteck/.svn
132K      linuxteck/Search/srdb-tests
392K      linuxteck/Search
2.8G      linuxteck/
2.8G      total
6. Block size output (KB/MB/GB)
# du -BK linuxteck
# du -BM linuxteck
# du -BG linuxteck

Kilobytes:
392K      linuxteck/Search
2921440K  linuxteck/

Megabytes:
1M        linuxteck/Search
2853M     linuxteck/

Gigabytes:
1G        linuxteck/Search
3G        linuxteck/
7. Sub-directory size
# du -h --max-depth=1 linuxteck

Output:
19M linuxteck/components
20K linuxteck/bin
17M linuxteck/libraries
964M linuxteck
8. Exclude files
# du -h --exclude="*.php" linuxteck
9. Last modified time
# du -ha --time log

I hope this article helps you learn du command options.

2 replies on “9 du Commands in Linux to Check Disk Usage (With Practical Examples)”

Leave a Reply

Your email address will not be published.

L