Best Linux you command with examples

In this article, you will learn how to use the Linux du command. The du command is a powerful command on Linux and the Unix operating system that checks the disk usage of files or directories.

Best Linux you command with examples

See the following Linux du command with examples:

We can use this to check the installed version of the Linux du command package you command with option – -Execution,

[[email protected] ~]# du --version   # To check Installed du Package Version
du (GNU coreutils) 5.97
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License .
There is NO WARRANTY, to the extent permitted by law.

Written by Torbjorn Granlund, David MacKenzie, Paul Eggert, and Jim Meyering.

Use the following command to check the disk usage of a specific file.

[[email protected] data]# du data.zip   # Check disk usage or size of a Particular file
1350084   data.zip

To check the disk usage of the contents of a directory, you can use the following command.

[[email protected] ~]# du data/*  # Checking Disk Usage of contents of a Directory
1350084 data/data.zip
2727652 data/kali-linux-2017.1-amd64.iso
668740  data/ubuntu-16.04-server-amd64.iso

OR you can use the du command with an argument -on to check the disk usage of all contents of a directory. Refer to the sample output below.

[[email protected] ~]# du -a data/  # Checking Disk Usage of all Contents of a Directory
1350084 data/data.zip
2727652 data/kali-linux-2017.1-amd64.iso
668740  data/ubuntu-16.04-server-amd64.iso
4746480 data/

Typically, the command prints the size of files and directories in disk blocks, which is not easy to understand. How to check disk usage of files and directories in human readable format (KB, MB, GB..etc ..) Use the du command with argument -H,

[[email protected] data]# du -h kali-linux-2017.1-amd64.iso  # Checking Size of the File in Human Readable Format
2.7G    kali-linux-2017.1-amd64.iso

From here I will explain all the arguments in human readable format.

To check the size of the entire contents of a directory in human-readable format, you can use the du command with an argument -Ah,

[[email protected] ~]# du -ah data/   # Checking all content of a Directory in Human Readable Format
1.3G    data/data.zip
2.7G    data/kali-linux-2017.1-amd64.iso
654M    data/ubuntu-16.04-server-amd64.iso
4.6G    data/

For information on checking the total size of a directory in human-readable format, see the following Linux du command.

[[email protected] ~]# du -h data/  # Checking Full Size of a Directory in Human Readable Format
4.6G    data/

If you try to check the disk usage of a directory that contains so much content and contains a maximum number of files and directories that cannot be displayed on a single page of the terminal, you can use fewer commands by using a filter with the Command you use. See the following command.

[[email protected] ~]# du -h /etc/ | less   # Using less command with du command
8.0K    /etc/pcmcia
8.0K    /etc/portreserve
172K    /etc/pki/java
32K     /etc/pki/rpm-gpg
4.0K    /etc/pki/rsyslog
4.0K    /etc/pki/CA/private
4.0K    /etc/pki/CA/certs
4.0K    /etc/pki/CA/crl
4.0K    /etc/pki/CA/newcerts
20K     /etc/pki/CA
180K    /etc/pki/ca-trust/extracted/java

you command with argument -c Returns the total size of the entire contents of the directory or files.

[[email protected] data]# du -ch *   # Checking Grand Total Size of a Directory with It's Content
1.3G    data.zip
2.7G    kali-linux-2017.1-amd64.iso
654M    ubuntu-16.04-server-amd64.iso
4.6G      total

Let’s check the total disk usage of all the contents of a directory in human readable format using the du command with argument -Oh,

[[email protected] ~]# du -ach data/   # Checking Grand Total Size of All content of a Directory 
1.3G    data/data.zip
2.7G    data/kali-linux-2017.1-amd64.iso
654M    data/ubuntu-16.04-server-amd64.iso
4.6G    data/
4.6G    total

To check disk usage in bytes, we can use the du command with an argument -b, Refer to the sample output below.

[[email protected] ~]# du -b data/*   # Checking Size in Bytes
1382479012      data/data.zip
2794307584      data/kali-linux-2017.1-amd64.iso
686817280       data/ubuntu-16.04-server-amd64.iso

you command with argument -k outputs the size of the files and directories in kilobytes (KB).

[[email protected] ~]# du -k data/*   # Checking Size in KB
1350084 data/data.zip
2727652 data/kali-linux-2017.1-amd64.iso
668740  data/ubuntu-16.04-server-amd64.iso

OR you can use the du command with an argument -BK to check the disk usage in KB.

[[email protected] data]# du -BK *   # Checking Size in KB
1350084K        data.zip
2727652K        kali-linux-2017.1-amd64.iso
668740K ubuntu-16.04-server-amd64.iso

To check the disk usage of files and directories in MB, you can use the du command with an argument -m,

[[email protected] data]# du -m *   # Checking Size in MB
1319    data.zip
2664    kali-linux-2017.1-amd64.iso
654     ubuntu-16.04-server-amd64.iso

OR you can use the du command with an argument -BM to check the size of files and directories in MB.

[[email protected] data]# du -BM *   # Checking Size in MB
1319M   data.zip
2664M   kali-linux-2017.1-amd64.iso
654M    ubuntu-16.04-server-amd64.iso

So you can check the disk usage in GigaByte with the argument -BG,

you command with argument – -Time Returns the date and time when files and directories were last modified.

[[email protected] ~]# du --time data/*   # Checking Last Modified date and time using du Command
4       2017-05-09 01:26        data/file1.txt
4       2017-05-09 01:26        data/file2.txt
4       2017-05-09 01:26        data/file3.txt
4       2017-05-09 01:26        data/file4.txt
4       2017-05-09 01:26        data/file5.txt

Suppose you have so many files or directories and want to check disk usage by excluding some files that you don’t want to check. Then you can do the same with the du command with the argument – exclude, For example, I have a directory with some here .iso and .Post Code Files. Now I just want to check the size .Post Code Want to exclude files and .iso Then we can use the following command.

[[email protected] data]# ls
data.zip  kali-linux-2017.1-amd64.iso  mydoc.zip  ubuntu-16.04-server-amd64.iso
[[email protected] data]# du -ah --exclude="*.iso"   # Checking Disk Usage by excluding .iso Files
1.3G    ./mydoc.zip
1.3G    ./data.zip
2.6G    .

OR if you want to check the size of .iso File and want to exclude .Post Code Then file the following command.

[[email protected] data]# du -ah --exclude="*.zip"   # Checking Disk Usage by excluding .zip Files
2.7G    ./kali-linux-2017.1-amd64.iso
654M    ./ubuntu-16.04-server-amd64.iso
3.3G    .

For command-related options, you can use the following command.

[[email protected] ~]# du --help   #  For more du command related options
Usage: du [OPTION]... [FILE]...
  or:  du [OPTION]... --files0-from=F
Summarize disk usage of each FILE, recursively for directories.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all             write counts for all files, not just directories
      --apparent-size   print apparent sizes, rather than disk usage; although
                          the apparent size is usually smaller, it may be
                          larger due to holes in (`sparse') files, internal
                          fragmentation, indirect blocks, and the like
  -B, --block-size=SIZE use SIZE-byte blocks
  -b, --bytes           equivalent to `--apparent-size --block-size=1'
  -c, --total           produce a grand total
  -D, --dereference-args  dereference FILEs that are symbolic links
      --files0-from=F   summarize disk usage of the NUL-terminated file
                          names specified in file F
  -H                    like --si, but also evokes a warning; will soon
                          change to be equivalent to --dereference-args (-D)
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
      --si              like -h, but use powers of 1000 not 1024
  -k                    like --block-size=1K
  -l, --count-links     count sizes many times if hard linked
  -m                    like --block-size=1M
  -L, --dereference     dereference all symbolic links
  -P, --no-dereference  don't follow any symbolic links (this is the default)
  -0, --null            end each output line with 0 byte rather than newline
  -S, --separate-dirs   do not include size of subdirectories
  -s, --summarize       display only a total for each argument
  -x, --one-file-system  skip directories on different file systems
  -X FILE, --exclude-from=FILE  Exclude files that match any pattern in FILE.
      --exclude=PATTERN Exclude files that match PATTERN.
      --max-depth=N     print the total for a directory (or file, with --all)
                          only if it is N or fewer levels below the command
                          line argument;  --max-depth=0 is the same as
                          --summarize
      --time            show time of the last modification of any file in the
                          directory, or any of its subdirectories
      --time=WORD       show time as WORD instead of modification time:
                          atime, access, use, ctime or status
      --time-style=STYLE show times using style STYLE:
                          full-iso, long-iso, iso, +FORMAT
                          FORMAT is interpreted like `date'
      --help     display this help and exit
      --version  output version information and exit

SIZE may be (or may be an integer optionally followed by) one of following:
kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.

Report bugs to .

OR For more information on the du command, see Command.

[[email protected] ~]# man du  # For more du command Related Informations

Also read: – Best chattr command to change file attributes – Make important files immutable

That’s all. In this article, we explained best Linux you command With examples. I hope you like this article. If you like this article, just share it. If you have any questions about this article, please comment.

Sidebar