DU command – The “disk usage” command is used to check the disk usage of files and folder under Unix/Linux system. It has a wide range of options. It’s one of the commonly using command by server/system administrators. A lot of switches are available with “du” command to manage things simply. Here I’m listing some important switches with du command to simply your workload on CLI.
Other switches are available with du. Please see man page or du --help for more details.
Most commonly using 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@EcLinux] du -s /home/server/
52 /home/server/
[root@EcLinux] du -sc /home/server/
52 /home/server/
52 total
[root@EcLinux] du -sch /home/server/
52K /home/server/
52K total
Displaying du command output with size specification
# du -(k,m,g)
k -> output displays in KB
m -> output displays in MB
g -> output displays in GB
Listing output with time stamp
# du –time
Command usage:
[root@EcLinux] du -sch –time /home/server/
52K 2013-09-02 18:39 /home/server/
52K 2013-09-02 18:39 total
Listing all files and directories, switch “a.”
# du -ah
a -> this switch displays disk usage of all individual files and directories.
Usage:
[root@EcLinux] du -ah /home/files/
0 /home/files/EcLinux5.doc
0 /home/files/EcLinux3.doc
0 /home/files/EcLinux4.txt
0 /home/files/EcLinux4.doc
0 /home/files/EcLinux2.txt
0 /home/files/EcLinux5.txt
4.0K /home/files/EcLinux1.doc
0 /home/files/EcLinux3.txt
4.0K /home/files/EcLinux1.txt
0 /home/files/EcLinux2.doc
12K /home/files/
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@EcLinux] du -ah –exclude=”*.txt” /home/files/
0 /home/files/EcLinux5.doc
0 /home/files/EcLinux3.doc
0 /home/files/EcLinux4.doc
4.0K /home/files/EcLinux1.doc
0 /home/files/EcLinux2.doc
8.0K /home/files/
Well, try this on your black screen 🙂
Write a comment if you have any questions.
Does any one know or experienced the output of “du -csh” mismatched with grand total ?
For ex: du -csh *
10M File_A
14M Dir_A
22M total
but expectation is 24 MB as total.