DU is the short form of Disk Usage.
The Linux du command is used to find out the disk usage in terms of file size and in human readable format. It can be used to get the size of the folders and the total usage. The usage of the command DU is very easy and some of them are explained below.
Pasted below are some usages of DU command.
1. Basic usage of du
# du 4 ./myfile 4 ./user/checkfile 4 ./john 12 ./sam 24 .
The command du -a is used to get the disk usage of all the files and directories.
# du -a 4 ./myfile 4 ./user/checkfile 4 ./john 12 ./sam 24 .
2. Display output in human-readable format
The command du -h is used to print the information in a human-readable format.
# du -ah 4.0K ./myfile 4.0K ./user/checkfile 4.0K ./john 12.0K ./sam 24K .
3. Display grand total of the space usage in the output.
The command du -c is used to get the grand total of its usage.
# du -ach 4.0K ./myfile 4.0K ./user/checkfile 4.0K ./john 12.0K ./sam 24K . 24K total
4. Display only the total count of the disk usage
To get the total amount of disk usage, the is command du -s
# du -sh 24K .
5. Customize the block
The output can be produced in such a way that the disk usage of the files and the directories are displayed on the basis of the block size. In the default setting, it displays the block size as KB(1024 Bytes). It can be changed to a different block size depending on the need.
# du -ach 4.0K ./myfile 4.0K ./user/checkfile 4.0K ./john 12.0K ./sam 24K . 24K total
When changing the block size to 2048(2KB), the output will be the following.
# du -ahc --block-size=2048 2 ./example 2 ./test1 2 ./redhat/demo 2 ./redhat/test 6 ./redhat 12 . 12 total
6. Display output in bytes
To display the output in bytes the command is du -b
# du -b 4096 ./myfile000 4096 ./admin/check 4096 ./one/two 12288 ./final 20529 .
7. Exclude particular types of file(s)
In order to not display the information about a particular type of file or files in the output the command du –exclude come into use
# ll total 16 -rw-r--r-- 1 root root 49 Sep 4 15:40 work -rw-r--r-- 1 root root 32 Sep 4 16:15 seeyou -rw-r--r-- 1 root root 0 Sep 4 16:19 work.doc -rw-r--r-- 1 root root 0 Sep 4 16:19 work1.txt -rw-r--r-- 1 root root 0 Sep 4 16:19 seeyou.doc -rw-r--r-- 1 root root 0 Sep 4 16:19 work2.txt
When using the du -exclude command the output will be as follows
# du -ah --exclude="*.txt" 4.0K ./user2 4.0K ./normalfile 0 ./check.doc 0 ./resume.doc 0 ./cv.doc 0 ./ace.doc 4.0K ./blue 4.0K ./office 4.0K ./office/desk 12K ./yellow 0 ./orange 28K .
8. Display the modification time and customize the display style
The commands du -time and du -time-style are the ones for the above.
# du -cbha --time 49 2013-09-04 15:40 ./car 4.0K 2013-09-04 15:39 ./buy 4.0K 2013-09-04 16:19 ./ticket.txt 8K 2013-09-04 16:26 total