du command in Linux with options

Hi friends! Today we will learn about du command in Linux with options, which is mainly used to check the space usage of the files and folders. We can check the size of files and folders in the disk space.

With the help of this, we can keep easily track the size of the files and folder.

Kindly refer the link so you can practice with us while learning the POST, it will take 40 to 50 seconds to boot the image

$ du
output: 
8	./test/tastethelinux
12	./test
4	./hacked
4	./tastethelinux
4	./level_1/level_2/level_3
8	./level_1/level_2
12	./level_1
4	./comp
8	./paper
4	./linux
52	.

So, from the output of du 2 things are missing first we can’t see the size whether it is kb, MB, or GB, and the second part that we are not able to see the files.

By default the size is kb, but to make it readable we will use -h option to get the output in a human-readable format.

h option for human readable

$ du -h
output: 
8.0K	./test/tastethelinux
12K	./test
4.0K	./hacked
4.0K	./tastethelinux
4.0K	./level_1/level_2/level_3
8.0K	./level_1/level_2
12K	./level_1
4.0K	./comp
8.0K	./paper
4.0K	./linux
52K	.

So, that’s cool, we are getting the proper output, but what if we want the continuous output?

–null option to get the continuous output

$ du --null -h
output:
8.0K  ./test/tastethelinux 12K  ./test 4.0K  ./hacked 4.0K 
 ./tastethelinux 4.0K  ./level_1/level_2/level_3 8.0K 
 ./level_1/level_2 12K ./level_1 4.0K  ./comp 8.0K  ./paper 4.0K 
 ./linux 52K  .

So, –null option doesn’t use the new line for the output, you can also use -0(Zero) option with du for the same output.

-a option to get the count for all files including directories.

$ du -h -a
output:
4.0K	./test/tastethelinux/taste.sh
8.0K	./test/tastethelinux
12K	./test
16K	.

On the above output you have taste.sh which is the file that I have created.

-B option to check the output in block size.

$ du -Bk
output:
8K	./test/tastethelinux
12K	./test
16K	.

So, now we can see the block size in KB because we are using k argument.

Let’s see what happens while using m argument on the same file and folder.

$ du -Bm
output:
1M	./test/tastethelinux
1M	./test
1M	.

By default, the value of Block size in MB is 1 MB, as we know that the files are in KB, but due to the default block size of MB is 1 MB we got such output.

-c option will show the total size.
$ du -c -h
output:
8.0K	./test/tastethelinux
12K	./test
16K	.
16K	total

So, we can see the red highlighted part in the output section that is “16K total” which is the total size of the current directory.

–inodes will show the output instead of Block size

$ du --inodes
output:
2	./test/tastethelinux
3	./test
4	.

This will show the inodes used in the current disk space.

-d option will show the depth of the folders.

$ du -h -d 1
output:
12K	./test
12K	./level_1
28K	.

So, we are able to see the level 1 folders, just notice the red highlighted part.

Now let’s go inside the one level in the directories by using -d 2 option

$ du -h -d 2 
output:
8.0K	./test/tastethelinux
12K	./test
8.0K	./level_1/level_2
12K	./level_1
28K	.

As we can see that the red highlighted part is in the level_2 folder, now let’s use option -d 3.

$ du -h -d 3
output:
8.0K	./test/tastethelinux
12K	./test
4.0K	./level_1/level_2/level_3
8.0K	./level_1/level_2
12K	./level_1
28K	.

We can see the level_3 folder, so the conclusion was when we use -d 1 then it shows only level_1 folder while using -d 2 it shows us the level_1 and level_2 directory as well, and while -d 3 it shows us the level_1, level_2, and the level_3 directory.

-S option will show the size of its directories, it will not show the size of its sub-directories.

We will see the difference by using -S option and without -S option.

$ du -h 
output:
8.0K	./test/tastethelinux
12K	./test
16K	.

So, the above output shows that this current whole directory is 16 KB.

When we create any directory in Linux by default size is 4 KB. And the du command always shows the size of the current directory.

Suppose you have the folder /exam/test/tastethelinux and you are inside the test folder then it will show the size of the exam folder which will be denoted by . (dot), as said earlier the folder size is of 4 KB.

  • 8.0K ./test/tastethelinux: This folder is of 8 KB because it contains tastethelinux folder 4 KB and test which is of 4 KB total size is 8 KB.
  • 12K ./test: This shows the total size of 12 KB because I have kept that in the exam folder which is of 4KB and already we have 8 KB of the above folder.
  • 16K . : This shows a total size of 16 KB because inside my home folder there is an exam folder.
$ du -h -S
output:
8.0K	./test/tastethelinux
4.0K	./test
4.0K	.

With the -S option it clearly shows the size of folders and we get the total size of 16 KB.

-t option will set the threshold size.

Suppose we have set the threshold value of 5k, it means that it will exclude all the files and folders which is less than 5k

Let’s see the difference between -t option and without using it.

$ du -h
output:
8.0K	./test/tastethelinux
12K	./test
4.0K	./tastethelinux
4.0K	./level_1/level_2/level_3
8.0K	./level_1/level_2
12K	./level_1
32K	.

Now we want to skip the folder that has the size 4 KB.

$ du -h -t5k
output:
8.0K	./test/tastethelinux
12K	./test
8.0K	./level_1/level_2
12K	./level_1
32K	.

–time option to show the time of the files and folder.

$ du -h --time
output:
8.0K	2020-04-20 15:06	./test/tastethelinux
12K	2020-04-25 19:51	./test
4.0K	2020-04-23 21:35	./tastethelinux
4.0K	2020-04-30 09:57	./level_1/level_2/level_3
8.0K	2020-04-30 09:57	./level_1/level_2
12K	2020-04-30 09:57	./level_1
32K	2020-04-30 21:09	.

Show while using the –time option it shows the modification time of any folders or files.

–exclude option to eliminate the files and folders.

$ du -h
output:
8.0K	./test/tastethelinux
12K	./test
4.0K	./tastethelinux
4.0K	./level_1/level_2/level_3
8.0K	./level_1/level_2
12K	./level_1
32K	.

So, now we have to exclude the folder level_1, let’s see how we will use the –exclude option.

$ du -h --exclude=level_1
output:
8.0K	./test/tastethelinux
12K	./test
4.0K	./tastethelinux
20K	.

-s option will only display the total size of the each files and folders.

$ du -sh * 
output:
0	learn_new
12K	level_1
0	quiz
4.0K	tastethelinux
12K	test

This shows the total size of all the files and folders that are in the current directory.

* is the wild card means to check the size of all files and folders.

du commands in Linux cheat sheet
To check the size of files and folder in human readable format

Syntax:
du [option] [argument]

Example:
#du -h files
#du -h folders
To check the output in a single line.

Syntax:
du [option]

Example:
#du --null
#du -0
To check all files and folder in Linux.

Syntax:
du [option]

Example:
#du -a
#du --all
To check all files and folder in Block size.

Syntax:
du [option] [argument]

Example:
#du -B k  -- o/p will be in KB.
#du -B m -- o/p will be in MB.
#du -B g  --  o/p will be in GB.
To check the total size of the current directory.

Syntax:
du [option]

Example:
#du -c
#du --total
To check the depth or level for a directory .

Syntax:
du [option] [levels]

Example:
#du -d 1 -- for level one directory.
#du -d 2 -- for level two directory.
#du -d 3 -- for level three directory.
To check the inodes instead of block size.

Syntax:
du [option]

Example:
#du --inodes
To check the size of it's directory only not it's sub-directory.

Syntax:
du [option]

Example:
#du -S
Displat only the total of an each arugment.

Syntax:
du [option]

Example:
#du -s
To Set the threshold size  

Syntax:
du [option] [size]

Example:
#du -t 5k //Show only those files and folders whose size is greater that 5 KB.  
#du --threshold=10k //Show only those files and folders whose size is greater that 10 KB.
To show the modification time with size.

Syntax:
du [option] [size]

Example:
#du --time
To exclude the size of the file.

Syntax:
du [option]=[directory]

Example:
#du --exclude=level_1
0%

Correct the Syntax friends?

Please select 5 correct answers

Correct! Wrong!

Which option we have to used to see the modification time?

Correct! Wrong!

Is du and df are the same command?

Correct! Wrong!

why -B options is use with du command?

Correct! Wrong!

which option is used to check the size of the depth or a level?

Please select 2 correct answers

Correct! Wrong!

Quiz for du command
Thanks for your valuable time!
To Learn more Basic command you can go to "LINUX BASIC COMMAND SECTION" and Spread the Knowledge Keep Supporting us! Follow us on our ID's: >> Instagram: @tastethelinux_official >>Facebook: https://fb.me/tastethelinuxofficial >>Twitter: @LinuxTaste

Share your Results:

you can learn about df command | you can learn about free command

Share the post du command in Linux and keep sharing

du command in linux sort by size, du command in linux in gb, du command in linux exclude directory, du command in linux in mb

3 Replies to “du command in Linux with options

Give your valuable time