du command, short for disk usage, is used to estimate file space usage.
The du command can be used to track the files and directories which are consuming excessive amount of space on hard disk drive.
Syntax :
du [OPTION]... [FILE]... du [OPTION]... --files0-from=F
Examples :
du /home/mandeep/test
Output:
44 /home/mandeep/test/data 2012 /home/mandeep/test/system design 24 /home/mandeep/test/table/sample_table/tree 28 /home/mandeep/test/table/sample_table 32 /home/mandeep/test/table 100104 /home/mandeep/test
Options :
-0, –null : end each output line with NULL
-a, –all : write count of all files, not just directories
–apparent-size : print apparent sizes, rather than disk usage.
-B, –block-size=SIZE : scale sizes to SIZE before printing on console
-c, –total : produce grand total
-d, –max-depth=N : print total for directory only if it is N or fewer levels below command line argument
-h, –human-readable : print sizes in human readable format
-S, -separate-dirs : for directories, don’t include size of subdirectories
-s, –summarize : display only total for each directory
–time : show time of last modification of any file or directory.
–exclude=PATTERN : exclude files that match PATTERN
Command usage examples with options :
- If we want to print sizes in human readable format(K, M, G), use -h option
du -h /home/mandeep/test Output:
44K /home/mandeep/test/data 2.0M /home/mandeep/test/system design 24K /home/mandeep/test/table/sample_table/tree 28K /home/mandeep/test/table/sample_table 32K /home/mandeep/test/table 98M /home/mandeep/test
- Use -a option for printing all files including directories.
du -a -h /home/mandeep/test
Output:
This is partial output of above command.4.0K /home/mandeep/test/blah1-new 4.0K /home/mandeep/test/fbtest.py 8.0K /home/mandeep/test/data/4.txt 4.0K /home/mandeep/test/data/7.txt 4.0K /home/mandeep/test/data/1.txt 4.0K /home/mandeep/test/data/3.txt 4.0K /home/mandeep/test/data/6.txt 4.0K /home/mandeep/test/data/2.txt 4.0K /home/mandeep/test/data/8.txt 8.0K /home/mandeep/test/data/5.txt 44K /home/mandeep/test/data 4.0K /home/mandeep/test/notifier.py
- Use -c option to print total size
du -c -h /home/mandeep/test
Output:
44K /home/mandeep/test/data 2.0M /home/mandeep/test/system design 24K /home/mandeep/test/table/sample_table/tree 28K /home/mandeep/test/table/sample_table 32K /home/mandeep/test/table 98M /home/mandeep/test 98M total
- To print sizes till particular level, use -d option with level no.
du -d 1 /home/mandeep/test
Output:
44 /home/mandeep/test/data 2012 /home/mandeep/test/system design 32 /home/mandeep/test/table 100104 /home/mandeep/test
Now try with level 2, you will get some extra directories
du -d 2 /home/mandeep/test
Output:
44 /home/mandeep/test/data 2012 /home/mandeep/test/system design 28 /home/mandeep/test/table/sample_table 32 /home/mandeep/test/table 100104 /home/mandeep/test
- Get summary of file system using -s option
du -s /home/mandeep/test
Output:
100104 /home/mandeep/test
- Get the timestamp of last modified using --time option
du --time -h /home/mandeep/test
Output:
44K 2018-01-14 22:22 /home/mandeep/test/data 2.0M 2017-12-24 23:06 /home/mandeep/test/system design 24K 2017-12-30 10:20 /home/mandeep/test/table/sample_table/tree 28K 2017-12-30 10:20 /home/mandeep/test/table/sample_table 32K 2017-12-30 10:20 /home/mandeep/test/table 98M 2018-02-02 17:32 /home/mandeep/test
References :
1) du wikipedia
2) du man entry
Recommended Posts:
- 'IPCS' command in Linux with examples
- select command in Linux with examples
- Sed Command in Linux/Unix with examples
- ZIP command in Linux with examples
- SORT command in Linux/Unix with examples
- Cat command in Linux with examples
- Head command in Linux with examples
- Tail command in Linux with examples
- wc command in Linux with examples
- tar command in Linux with examples
- atrm command in Linux with examples
- bc command in Linux with examples
- AWK command in Unix/Linux with examples
- tr command in Unix/Linux with examples
- mv command in Linux with examples
- Paste command in Linux with examples
- comm command in Linux with examples
- cmp Command in Linux with examples
- cut command in Linux with examples
- cp command in Linux with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai

