The Linux “du” (Disk Usage) is a standard Unix/Linux command, used to check the information of disk usage of files and directories on a machine.
The du command has many parameter options that can be used to get the results in many formats. The du command also displays the files and directory sizes in a recursive manner.

This article explains 10 useful “du” commands with their examples, which might help you to find out the sizes of files and directories in Linux. The information provided in this article is taken from the man pages of du command.
Read Also:
- 12 “df” Command to Check Linux System Disk Space
- Agedu – A Useful Tool for Tracking Down Wasted Disk Space in Linux
How to Find the Size of a Directory in Linux
1. To find out the disk usage summary of a /home/tecmint directory tree and each of its subdirectories. Enter the command as:
[[email protected]]# du /home/tecmint 40 /home/tecmint/downloads 4 /home/tecmint/.mozilla/plugins 4 /home/tecmint/.mozilla/extensions 12 /home/tecmint/.mozilla 12 /home/tecmint/.ssh 689112 /home/tecmint/Ubuntu-12.10 689360 /home/tecmint
The output of the above command displays the number of disk blocks in the /home/tecmint directory along with its sub-directories.
How to Find the Directory Size in Human Readable Format
2. Using the “-h” option with the “du” command provides results in “Human Readable Format“. This means you can see sizes in Bytes, Kilobytes, Megabytes, Gigabytes, etc.
[[email protected]]# du -h /home/tecmint 40K /home/tecmint/downloads 4.0K /home/tecmint/.mozilla/plugins 4.0K /home/tecmint/.mozilla/extensions 12K /home/tecmint/.mozilla 12K /home/tecmint/.ssh 673M /home/tecmint/Ubuntu-12.10 674M /home/tecmint
How to Find Total Size of a Directory in Linux
3. To get the summary of a grand total disk usage size of a directory uses the option “-s” as follows.
[[email protected]]# du -sh /home/tecmint 674M /home/tecmint
4. Using the “-a” flag with the “du” command displays the disk usage of all the files and directories.
[[email protected]]# du -a /home/tecmint 4 /home/tecmint/.bash_logout 12 /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz 24 /home/tecmint/downloads/Phpfiles-org.tar.bz2 40 /home/tecmint/downloads 12 /home/tecmint/uploadprogress-1.0.3.1.tgz 4 /home/tecmint/.mozilla/plugins 4 /home/tecmint/.mozilla/extensions 12 /home/tecmint/.mozilla 4 /home/tecmint/.bashrc 689108 /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso 689112 /home/tecmint/Ubuntu-12.10 689360 /home/tecmint
5. Using the “-a” flag along with “-h” displays disk usage of all files and folders in a human-readable format. The below output is easier to understand as it shows the files in Kilobytes, Megabytes, etc.
[[email protected]]# du -ah /home/tecmint 4.0K /home/tecmint/.bash_logout 12K /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz 24K /home/tecmint/downloads/Phpfiles-org.tar.bz2 40K /home/tecmint/downloads 12K /home/tecmint/uploadprogress-1.0.3.1.tgz 4.0K /home/tecmint/.mozilla/plugins 4.0K /home/tecmint/.mozilla/extensions 12K /home/tecmint/.mozilla 4.0K /home/tecmint/.bashrc 673M /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso 673M /home/tecmint/Ubuntu-12.10 674M /home/tecmint
6. Find out the disk usage of a directory tree with its subtree in Kilobyte blocks. Use the “-k” (displays size in 1024 bytes units).
[[email protected]]# du -k /home/tecmint 40 /home/tecmint/downloads 4 /home/tecmint/.mozilla/plugins 4 /home/tecmint/.mozilla/extensions 12 /home/tecmint/.mozilla 12 /home/tecmint/.ssh 689112 /home/tecmint/Ubuntu-12.10 689360 /home/tecmint
7. To get the summary of disk usage of directory tree along with its subtrees in Megabytes (MB) only. Use the option “-mh” as follows. The “-m” flag counts the blocks in MB units and “-h” stands for human-readable format.
[[email protected]]# du -mh /home/tecmint 40K /home/tecmint/downloads 4.0K /home/tecmint/.mozilla/plugins 4.0K /home/tecmint/.mozilla/extensions 12K /home/tecmint/.mozilla 12K /home/tecmint/.ssh 673M /home/tecmint/Ubuntu-12.10 674M /home/tecmint
8. The “-c” flag provides a grand total usage disk space at the last line. If your directory is taken 674MB space, then the last last two lines of the output would be.
[[email protected]]# du -ch /home/tecmint 40K /home/tecmint/downloads 4.0K /home/tecmint/.mozilla/plugins 4.0K /home/tecmint/.mozilla/extensions 12K /home/tecmint/.mozilla 12K /home/tecmint/.ssh 673M /home/tecmint/Ubuntu-12.10 674M /home/tecmint 674M total
How to Exclude Files with du Command
9. The below command calculates and displays the disk usage of all files and directories, but excludes the files that match the given pattern. The below command excludes the “.txt” files while calculating the total size of a directory. So, this way you can exclude any file formats by using the flag “-–exclude“. See the output there is no txt files entry.
[[email protected]]# du -ah --exclude="*.txt" /home/tecmint 4.0K /home/tecmint/.bash_logout 12K /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz 24K /home/tecmint/downloads/Phpfiles-org.tar.bz2 40K /home/tecmint/downloads 12K /home/tecmint/uploadprogress-1.0.3.1.tgz 4.0K /home/tecmint/.bash_history 4.0K /home/tecmint/.bash_profile 4.0K /home/tecmint/.mozilla/plugins 4.0K /home/tecmint/.mozilla/extensions 12K /home/tecmint/.mozilla 4.0K /home/tecmint/.bashrc 24K /home/tecmint/Phpfiles-org.tar.bz2 4.0K /home/tecmint/geoipupdate.sh 4.0K /home/tecmint/.zshrc 120K /home/tecmint/goaccess-0.4.2.tar.gz.1 673M /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso 673M /home/tecmint/Ubuntu-12.10 674M /home/tecmint
How to Find Directory Usage By Modification Time
10. Display the disk usage based on a modification of time, use the flag “–time” as shown below.
[[email protected]]# du -ha --time /home/tecmint 4.0K 2012-10-12 22:32 /home/tecmint/.bash_logout 12K 2013-01-19 18:48 /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz 24K 2013-01-19 18:48 /home/tecmint/downloads/Phpfiles-org.tar.bz2 40K 2013-01-19 18:48 /home/tecmint/downloads 12K 2013-01-19 18:32 /home/tecmint/uploadprogress-1.0.3.1.tgz 4.0K 2012-10-13 00:11 /home/tecmint/.bash_history 4.0K 2012-10-12 22:32 /home/tecmint/.bash_profile 0 2013-01-19 18:32 /home/tecmint/xyz.txt 0 2013-01-19 18:32 /home/tecmint/abc.txt 4.0K 2012-10-12 22:32 /home/tecmint/.mozilla/plugins 4.0K 2012-10-12 22:32 /home/tecmint/.mozilla/extensions 12K 2012-10-12 22:32 /home/tecmint/.mozilla 4.0K 2012-10-12 22:32 /home/tecmint/.bashrc 24K 2013-01-19 18:32 /home/tecmint/Phpfiles-org.tar.bz2 4.0K 2013-01-19 18:32 /home/tecmint/geoipupdate.sh 4.0K 2012-10-12 22:32 /home/tecmint/.zshrc 120K 2013-01-19 18:32 /home/tecmint/goaccess-0.4.2.tar.gz.1 673M 2013-01-19 18:51 /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso 673M 2013-01-19 18:51 /home/tecmint/Ubuntu-12.10 674M 2013-01-19 18:52 /home/tecmint
Read Also :
A kilobyte is 1000 bytes, always has (referring to the
-k
switch part). A kilo is always a unit of 1000 (e.g. a kilometer is also 1000 meters). A kibibyte is 1024 bytes. I know that Americans aren’t used to the metric system, but please, get it right when you do use it. I see these mistakes happen in blogs like these all the time…How can i find the 1st five largest in the file
/etc
.@Jilson,
Check this article to Find Out Top Directories and Files Disk Space in Linux.
If I want to calculate the size of files with particular extensions in a directory. How can I calculate it?
Does any one know or experienced the output of “du -csh” mismatched with grand total ?
For ex: du -csh *
10M File_A
14M Dir_A
22M total
but expectation is 24 MB as total.
There can be two reasons (that I can think of):
One is Rounding:
The sizes are quite quickly rounded up (a few k over the mark is enough).
10M File_A – might be 9.2M
14M Dir_A – might be 13.2M
23M total – because that adds up to 22.4, which again is rounded up.
But I think that can’t explain it fully.
It might be because you simplified your example and there are more of these files/directories of a few k which all get rounded up to 1M.
– The functioning of *
Another way is that there are files/directories starting with . in your main directory.
These are not shown in the list when you use *, but they are calculated in the total of the main directory.
I would like to mention also this combination, in order to find the biggest sub-folders in current location:
du -h –max-depth=1
thanks
Yes – I ended up going to an ancient site looking for that switch – it should be like number 2 on the list.
fyi: On some systems – freebsd is particular, depth is just -d [depth] – so “du -d 1 -h” is the secret sauce for the question ‘wtf happened to my space?’
Is is possible to collect historical data analysis of disk space usage per user ?
@rlinux,
No you can’t use du (disk usage) command to get the disk space usage per user, yes but you can do use some command-line tricks with the help of find and awk command to find out the disk space usage for all users on the system including root user, here is the command.
But i need want to get the historical disk space usage, not current usage.
You could start a cron to run this command at different times to log the historical data
find / -printf “%u %s\n” | awk ‘{user[$1]+=$2}; END{ for( i in user) print i ” ” user[i]}’
find / -printf “%u %s\n” | awk ‘{user[$1]+=$2}; END{ for( i in user) print i ” ” user[i]}’ > /yourlogdir/log_`date +_%m_%d_%Y_%H%M%S`
Another nice option is to sort by size: du -h * | sort -h
that’s a very desirable addition!
how to find du of / ie when I ran du -sh / it gives du: cannot access `./proc/14498/task/14518/fdinfo/35147′: No such file or directory
du: cannot access `./proc/14498/task/14518/fdinfo/35156′: No such file or directory
@Ashish,
du command can’t be run on partitions, it just meant for showing disk usage of only files/directories…
Thanks for tips. Well explain ans example
very nice work. It helped me.