Du Command
Du Command
Related Articles
du Command in LINUX
Last Updated : 15 May, 2019
While working on LINUX, there might come a situation when you want to transfer a set of
files or the entire director y. In such a case, you might wanna know the disk space
consumed by that par ticular director y or set of files. A s you are dealing with LINUX, there
exists a command line utility for this also which is du command that estimates and
So, in simple words du command-line utility helps you to find out the disk usage of set of
files or a director y.
//syntax of du command
du [OPTION]... [FILE]...
or
du [OPTION]... --files0-from=F
where OP TION refers to the options compatible with du command and FILE refers to the
Using du command
Suppose there are two files say k t.txt and pt.txt and you want to know the disk usage of
these files, then you can simply use du command by specif ying the file names along with
it as:
We use cookies to ensure you have the best browsing experience on our website. By using our Got It !
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
https://www.geeksforgeeks.org/du-command-linux/ 1/12
7/24/2021 du Command in LINUX - GeeksforGeeks
//using du command
So, as shown above du displayed the disk space used by the corresponding files.
Now, the displayed values are actually in the units of the first available SIZE from – -
variables and if not in this format then units are default to 1024 bytes (or 512 if
POSIXLY_CORRECT is set).
Don’t get puzzled from the above paragraph. We can simply use -h option to force du to
-a, – -all option : This option produces counts as output for all files, not for just
directories.
– -apparent-size option : This prints the apparent sizes for the files and not the disk
usage which can be larger due to holes in files (sparse), internal fragmentation and
-B, – -block-size=SIZE option : This option causes the size to scale by SIZE like -BM
-D, – -dereference-args option : This option is used to dereference only the symbolic
file names specified in the file F and if the file F is “-” then read names from the
standard input.
We use cookies to ensure you have the best browsing experience on our website. By using our
-h, – -human-readable option : This prints the sizes in human readable format i.e in
Got It !
site,rounding
you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
values and using abbreviations like 1 K and this is the most of ten used option
https://www.geeksforgeeks.org/du-command-linux/ 2/12
7/24/2021 du Command in LINUX - GeeksforGeeks
with du.
– -si option: This is much similar to the -h option but uses power of 1000 and not of
1024.
-l, – -count-links option : This count sizes many times if files are hard-linked.
-P, – -no-dereference option : This option tells du not to follow any symbolic links
-0, –null option : This ends each output line with 0 byte rather than a newline.
-S, – -separate-dirs option : This causes the output not to include the size of
subdirectories.
-s, – -summarize option : This option will allow to display a total only for each
argument.
-x, – -one-file-system option : This will cause du to skip directories on different file
systems.
-X, – -exclude-from=FILE option : Exclude files that match any pattern given in FILE.
– -exclude=PAT TERN option : It will exclude files that match PAT TERN.
-d, – -max-depth=N option : Print the total for a director y (or file, with –all) only if it is
N or fewer levels below the command line argument; –max-depth=0 is the same as –
summarize.
– -time option : This will show the time of the last modification of any file in the
– -time=WORD option : This shows time as WORD instead of modification time :atime,
– -time-style=ST YLE option : this shows time using ST YLE: full-iso, long-iso, iso, or
1. Using -h option : A s mentioned above, -h option is used to produce the output in human
readable format.
//using -h with du
We use cookies to ensure you have the best browsing experience on our website. By using our Got It !
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
https://www.geeksforgeeks.org/du-command-linux/ 3/12
7/24/2021 du Command in LINUX - GeeksforGeeks
2. Using du to show disk usage of a director y : Now, if you will pass a director y name say
kar tik as an argument to du it will show the disk usage info of the input director y kar tik
$du kartik
4 kartik/thakral
24 kartik
A bove the disk usage info of the director y kar tik and its sub-director y thakral is
displayed.
3. Using -a option : now, as seen above only the disk usage info of director y
kar tik and its sub-director y thakral is displayed but what if you also want to know the
disk usage info of all the files present under the director y kar tik. For this, use -a option.
//using -a with du
$du -a kartik
8 kartik/kt.txt
4 kartik/pt.txt
4 kartik/pranjal.png
We use cookies to ensure you have the best browsing experience on our website. By using our Got It !
4 kartik/thakral.png
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
https://www.geeksforgeeks.org/du-command-linux/ 4/12
7/24/2021 du Command in LINUX - GeeksforGeeks
4 kartik/thakral
24 kartik
//using -c with du
/* at the end
total is displayed
for the disk usage */
5. Using – -time option : This option is used to display the last modification time in the
output of du.
6. Using – -exclude=PAT TERN option : In one of the example above, all the files disk
We use cookies to ensure you have the best browsing experience on our website. By using our Got It !
usage related info was displayed of director y kar tik. Now, suppose you want to know the
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
https://www.geeksforgeeks.org/du-command-linux/ 5/12
7/24/2021 du Command in LINUX - GeeksforGeeks
info of .txt files only and not of .png files, in that case to exclude the .png pattern you can
7. Using – -max-depth=N option : Now, this option allows you to limit the output of du to a
Suppose you have a director y named FRIENDS under which you have sub-directories as
FRIENDS/college and FRIENDS/school and also under sub-director y college you have
https://www.geeksforgeeks.org/du-command-linux/ 6/12
7/24/2021 du Command in LINUX - GeeksforGeeks
24 FRIENDS
usage of the NUL-terminated file names specified in the file F and if the file F is “-” then
Let ’s use this option for taking input from STDIN as:
$pwd
/home/kartik
$ls
kt.txt pt.txt thakral
$du --files0-from=-
kt.txt8 kt.txt
pt.txt4 pt.txt
https://www.geeksforgeeks.org/du-command-linux/ 7/12
7/24/2021 du Command in LINUX - GeeksforGeeks
Applications of du command
It can be used to find out the disk space occupied by a par ticular director y in case of
There also exists some other ways like df command to find the disk usage but they all
lack du ability to show the disk usage of individual directories and files.
It can also be used to find out quickly the number of sub-directories present in a
director y.
Let ’s take a simple example of using du with sor t command so that the output produced
$du -a kartik
8 kartik/kt.txt
4 kartik/pt.txt
4 kartik/pranjal.png
4 kartik/thakral.png
4 kartik/thakral
24 kartik
https://www.geeksforgeeks.org/du-command-linux/ 8/12
7/24/2021 du Command in LINUX - GeeksforGeeks
4 kartik/thakral
8 kartik/kt.txt
24 kartik
The sor t command along with -n option used causes to list the output in numeric order
In this way du can be used to arrange the output according to the size.
Like 0
Previous Next
ADVERTISEMENT BY ADRECOVER
We use cookies to ensure you have the best browsing experience on our website. By using our Got It !
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
https://www.geeksforgeeks.org/du-command-linux/ 9/12
7/24/2021 du Command in LINUX - GeeksforGeeks
12, Apr 16
to a specific directory.
28, May 17
Ar ticle Contributed By :
Kartik Thakral
@Kartik Thakral
https://www.geeksforgeeks.org/du-command-linux/ 10/12
7/24/2021 du Command in LINUX - GeeksforGeeks
Report Issue
Improve Article
Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
Load Comments
ADVERTISEMENT BY ADRECOVER
Company Learn
About Us Algorithms
Careers Data Structures
Privacy Policy Languages
Contact Us CS Subjects
Copyright Policy Video Tutorials
Practice Contribute
Courses Write an Article
Company-wise Write Interview Experience
Topic-wise Internships
How
We use cookies to ensure youtohave
begin?
the best browsing experience on our website. By using ourVideos Got It !
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
https://www.geeksforgeeks.org/du-command-linux/ 11/12
7/24/2021 du Command in LINUX - GeeksforGeeks
We use cookies to ensure you have the best browsing experience on our website. By using our Got It !
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
https://www.geeksforgeeks.org/du-command-linux/ 12/12