In my previous tutorial i have discussed about df command and the use of the command, same as df , du also a disk management command with different functionalities and use case. So in this chapter will discuss what really du command is and how is differs from df command.
As i have already discussed about it always required for an end user and administrator to manage a disk, so du is also helps to mange the disk in UNIX like operating system. In this tutorial lets learn how to check disk-space in linux using the df command.
du(disk usage):
Disk usage in short known as du command, we invoke to find out the consumption of a specific directory tree rather that an the complete file system. du is the command we often need as it helps us to estimate disk usage of the set of FILEs, recursively for directories.
How to Use the du command ?
The general syntax for disk usage command is as below,
du [OPTION]… [FILE]… du [OPTION]... --files0-from=F
If the given FILE
is a directory, du
will summarize disk usage of each file and subdirectory in that directory. If no FILE
is specified, du
will report the disk usage of the current working directory.
Options ::
-a (all) | write counts for all files, not just directories |
-c (total) | produces a grand total |
-h (human readable) | prints sizes in human readable format (e.g., 1K 234M 2G) |
–time | shows time of the last modification of any file in the directory, or any of its subdirectories |
-k | shows like –block-size=1K |
In above table i have mentioned few of the important arguments the we invoke with disk usage command. Now let’s see some of the examples.
When disk usage command invoked without any argument ?
For example purpose i have shown the details of my Document directory, you can check the usage of the particular directory accordingly.
$ du Documents/ Output: 4 Documents/Test 2077036 Documents/
Now i run the du command to see all the available file details in my Document directory with -a argument.
$ du -a Documents/ Output : (In Blocks) 28 Documents/Capture2.PNG 2076708 Documents/ubuntu-18.04.4-desktop-amd64.iso 4 Documents/program.py 60 Documents/Capture8.PNG 4 Documents/Test 4 Documents/.~lock.Untitled 1.odt# 52 Documents/Capture5.PNG 44 Documents/Capture6.PNG 48 Documents/Capture3.PNG 32 Documents/Capture1.PNG 48 Documents/Capture7.PNG 2077036 Documents/
But if you want to see the same output in (human readable format KB, MB, GB etc.). Usually To do that, use the -h
option.
$ du -ah Documents/ Output: 28K Documents/Capture2.PNG 2.0G Documents/ubuntu-18.04.4-desktop-amd64.iso 4.0K Documents/program.py 60K Documents/Capture8.PNG 4.0K Documents/Test 4.0K Documents/.~lock.Untitled 1.odt# 52K Documents/Capture5.PNG 44K Documents/Capture6.PNG 48K Documents/Capture3.PNG 32K Documents/Capture1.PNG 48K Documents/Capture7.PNG 2.0G Documents/
The nature of du utility is to read the disk space used by the directory or file. To find the apparent size of a file, use the --apparent-size
switch. The “apparent size” of a file is how much data is actually in the file.
$ du -sh --apparent-size Documents/ Output 2.0G Documents/
I hope you should have got basic information about disk usage command, and if you want more options or ideas on du command you can run man disk usage in your terminal. Learn about df command click here.
2 Comments on “What is du command in Linux ? Disk Usage !”