The Linux command du stands for disk usage which is used to check the amount of disk storage any particular directory or file is using. By default, the simple command:
du
Would return the disk usage in God-knows-what-unit of each of the directories in the current working directory and those beneath them – in a recursive manner. If you happen to have lots of them, the returned stats would be scrolling down crazily which barely makes it any useful.
Even if you have specified a specific directory such as "somedir":
du somedir
It still works in this uncomfortable way.
The solution is to use the -sh switch, the one switch a beginner will ever need:
du -sh
Which simply returns the amount of disk space the current directory and all those stuff in it are using as a whole, something like:
2.4G
Much much more intuitive and readable.
By:
du -sh somedir
You can find out how much disk storage directory "somedir" is using:
101M somedir
To get all the subsequent / child directories disk usage from the current directory, simply use the asterisk:
du -sh *
It will then list the disk usage of all of them (but not recursively) one by one in a very readable manner:
8.0K dir1
1.4G dir2
135M dir3
You should also read:
- Linux: How to find all the files containing a particular text string?
- Linux: Find files changed or modified within 1 day or older than 1 day
- How to count files (get the number of files) under a directory in Linux?
- Essential SSH – 19 Linux SSH Commands You Simply Cannot Live Without
- Linux: Change Directory or CD to the Previous Directory / Last Path


Facebook
Twitter
Google Plus
{ 4 comments… read them below or add one }
This can be a useful thing to web administrators.
I have a website and I want to check how much a folder /upload/ is consuming space. This folder contains, mostly, images of hotels etc.
I would use your “du” command this way, please comment if I am wrong,
du -sh /public_html/upload/*
Since I do not have a direct shell access, I would put it into a php file and then open that php in the browser.
I think that would do. :)
how to get the list of top space consuming directories?
@pradebban Excellent question. I’ve seen it asked all over the net. The best answer I’ve ever seen is as follows:
du –max-depth=0 -k * | sort -nr | awk ‘{ if($1>=1024*1024) {size=$1/1024/1024; unit=”G”} else if($1>=1024) {size=$1/1024; unit=”M”} else {size=$1; unit=”K”}; if(size<10) format="%.1f%s"; else format="%.0f%s"; res=sprintf(format,size,unit); printf "%-8s %s\n",res,$2 }'