Skip to content
Home » Linux Unix » How to Estimate File Space Usage by du

How to Estimate File Space Usage by du

Command "du" is very common tool to calculate the overall used space in Unix and very useful in tracing potential growing files and directories. For example, we would like to know the used size in kilobytes of all files in a specific directory /usr. We use "du -k".
[root@www ~]# cd /usr
[root@www usr]# du -k
4       ./lib/java-1.5.0
4       ./lib/jvm-commmon
8       ./lib/rpm/platform/noarch-linux
8       ./lib/rpm/platform/i686-linux
8       ./lib/rpm/platform/pentium3-linux
8       ./lib/rpm/platform/i386-linux
8       ./lib/rpm/platform/geode-linux
8       ./lib/rpm/platform/pentium4-linux
8       ./lib/rpm/platform/i586-linux
8       ./lib/rpm/platform/x86_64-linux

It lists all files with calculated size,  but it will become annoying when there're thousands of files.

To solve this, we can sort it by number reversely and focus on the first 10.
[root@www usr]# du -k | sort -rn | head
2331992 .
999088  ./share
414808  ./lib
391924  ./lib64
330388  ./share/locale
201220  ./bin
196656  ./local
196520  ./local/Application
188236  ./local/Application/plugins
185184  ./lib/tools

Now, the output will be more focused, you can easily identify the directories or files.

If you just want a number, you can sum them up by adding a "s" option.
[root@www usr]# du -sk
2331992 .

It gives you  a number of overall used space in the directory.

But how about the subdirectories? You can add a wildcard "*" to represent them.
[root@www usr]# du * -sk
201220  bin
4       etc
4       games
7400    include
414808  lib
391924  lib64
44056   libexec
196656  local
28304   sbin
999088  share
48524   src
0       tmp

The "*" is the tip to know a deeper result among subdirectories.

Leave a Reply

Your email address will not be published. Required fields are marked *