DU is the short form of Disk Usage.
The linux du command is used to summarize or find out the disk usage in terms of file size. It can be used to get the size of the folders and the total disk usage.
The following are some of the du commands that we normally use.
- Basic usage of du
# du 4 ./test1 4 ./redhat/demo 4 ./redhat/test 12 ./redhat 24 .
The command du -a is used to get the disk usage of all the files and directories.# du -a 4 ./example 4 ./test1 4 ./redhat/demo 4 ./redhat/test 12 ./redhat 24 .
- Display output in human readable format
The command du -h is used to print the information in human readable format.# du -ah 4.0K ./example 4.0K ./test1 4.0K ./redhat/demo 4.0K ./redhat/test 12K ./redhat 24K .
- Display grand total of the space usage in the output.
The command du -c is used to get the grand total of the disk usage.# du -ach 4.0K ./example 4.0K ./test1 4.0K ./redhat/demo 4.0K ./redhat/test 12K ./redhat 24K . 24K total
- Display only the total count of the disk usage
The command du -s is used to get the total amount of the disk usage.# du -sh 24K .
- Customize the block
The output can be produced in such a way that the disk usage of the files and the directories are dispalyed in the basis of the block size. In the defualt 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 ./example 4.0K ./test1 4.0K ./redhat/demo 4.0K ./redhat/test 12K ./redhat 24K . 24K total
When change 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
- Display output in bytes
The command du -b is used to display the output in bytes.# du -b 4096 ./test1 4096 ./redhat/demo 4096 ./redhat/test 12288 ./redhat 20529 .
- Exclude particular types of file(s)
The command du –exclude is used to not displaying the information about a particular type of the file or files in the output.# ll total 16 -rw-r--r-- 1 root root 49 Sep 4 15:40 example -rw-r--r-- 1 root root 32 Sep 4 16:15 hello -rw-r--r-- 1 root root 0 Sep 4 16:19 hello1.doc -rw-r--r-- 1 root root 0 Sep 4 16:19 hello1.txt -rw-r--r-- 1 root root 0 Sep 4 16:19 hello2.doc -rw-r--r-- 1 root root 0 Sep 4 16:19 hello2.txt -rw-r--r-- 1 root root 0 Sep 4 16:19 hello3.doc -rw-r--r-- 1 root root 0 Sep 4 16:19 hello3.txt -rw-r--r-- 1 root root 0 Sep 4 16:19 hello4.doc -rw-r--r-- 1 root root 0 Sep 4 16:19 hello4.txt -rw-r--r-- 1 root root 0 Sep 4 16:19 hello5.doc -rw-r--r-- 1 root root 0 Sep 4 16:19 hello5.txt drwxr-xr-x 4 root root 4096 Sep 4 15:42 redhat drwxr-xr-x 2 root root 4096 Sep 4 15:39 test1
When using the du -exclude command the output will be as follows# du -ah --exclude="*.txt" 4.0K ./example 4.0K ./test1 0 ./hello5.doc 0 ./hello2.doc 0 ./hello3.doc 0 ./hello4.doc 4.0K ./hello 4.0K ./redhat/demo 4.0K ./redhat/test 12K ./redhat 0 ./hello1.doc 28K .
- Display the modification time and customize the display style
The above can be done using the command du -time and du -time-style commands.# du -cbha --time 49 2013-09-04 15:40 ./example 4.0K 2013-09-04 15:39 ./test1 0 2013-09-04 16:19 ./hello5.txt 0 2013-09-04 16:19 ./hello5.doc 32 2013-09-04 16:15 ./hello 4.0K 2013-09-04 15:42 ./redhat/demo 4.0K 2013-09-04 15:38 ./redhat/test 12K 2013-09-04 15:42 ./redhat 21K 2013-09-04 16:26 . 21K 2013-09-04 16:26 total