Blog

Some useful switches for “du – disk usage”

Tags: directorydisk usagedufilesLinux

Published on: June 6, 2017 by Liya Gigi

Some useful switches for “du – disk usage”

Scenario:

As we know, du command is used to check the disk usage of files and folders under Linux system. There are a lot of switches available for du among which here I am trying to explain the most common switches used.

As you know, one can easily checks the switches available for du by looking at the man page for du or by executing the command du –help .

Here I am trying to provide some basic guidelines about commonly used switches so that you can use them whenever in need.

Most commonly used form

# du -sch

h -> human readable format.
c -> display a total size usage at the end of result.
s -> display total size of a file or total size of all files in a directory.

Usage:

root@server [/home/abl]# du -s /home/abl
213932 /home/abl
root@server [/home/abl]# du -sh /home/abl
209M /home/abl
root@server [/home/abl]# du -sch /home/abl
209M /home/abl
209M total

Listing all files and directories, switch “a”

# du -ah

a -> this switch displays disk usage of all individual files and directories.

Usage:

root@server [/home/abl/etc]# du -ah /home/abl/etc | tail
0 /home/abl/etc/wis.com/quota
4.0K /home/abl/etc/wis.com
0 /home/abl/etc/ftpquota
0 /home/abl/etc/quota
4.0K /home/abl/etc/cacheid
0 /home/abl/etc/ablo.com/passwd
0 /home/abl/etc/ablo.com/shadow
0 /home/abl/etc/ablo.com/quota
4.0K /home/abl/etc/ablo.com
28K /home/abl/etc

Exclude something from the command output, using –exclude

# du –exclude

-–exclude -> This switch will avoid the particular file name that we have mentioned.
In the below example du -ah avoid files ending with .txt (–exclude=”*.txt”)

 root@server [/home/abl/etc]# du -ah –exclude=”quota” /home/abl/etc | tail
4.0K /home/abl/etc/wis.abl.com
0 /home/abl/etc/wis.com/passwd
0 /home/abl/etc/wis.com/shadow
4.0K /home/abl/etc/wis.com
0 /home/abl/etc/ftpquota
4.0K /home/abl/etc/cacheid
0 /home/abl/etc/abl.com/passwd
0 /home/abl/etc/ablogsite.com/shadow
4.0K /home/abl/etc/ablogsite.com
28K /home/abl/etc

Display modification time of files/folders, using –time

# du –time

–time ->This option shows the modification date and time of the file/directories.

root@server [/home/user/folder]# du -sch –time *
1.8M    2017-05-19 00:32    Folder 1
248M    2017-05-06 07:35   Folder 2
40K       2016-12-15 15:05   Folder 3
32K       2017-04-27 15:46   File.pdf
250M    2017-05-19 00:32    total

This switches should help you get the disk usage of the files in any directory.

There are few other options for du which are worth trying. You can view its details checking the man page of du.

Get 24/7 expert server management

Category : Howtos, Linux, Troubleshooting

Liya Gigi

Liya Gigi

Liya is a Linux professional working on Linux and open source. Currently working as a System Administrator. She is well versed in WordPress and loves working with WordPress websites.In her free time, she loves blogging, travelling, photography and music.

You may also read:

Comments

Add new commentSIGN IN

Let's Connect

Categories

Your Cart

Cart is empty.

Subtotal
₹0.00
APPLY
0
Send this to a friend