Friday, 6 June 2014

Find disk usage by folder in Linux EXLAINED!

In case that you have running low on space on your server, it is crucial to find where is greatest disk usage!

First find on what mount point low space is!

server]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/rootvg-rootlv   60G  5.9G   51G  11% /
/dev/sda1                  486M   42M  419M  10% /boot
/dev/mapper/rootvg-optlv    60G   59G   503M  99% /opt

On this server we have usage on /opt mount point.

Go there

server#cd /opt

List folder


If your lack of space happened suddenly, first find what is created last! For instance, in last 2 minutes!

server#find . -mmin -2

Check size of showed files. Check size of folders where those files are!
If no files are shown, extend time of search. Replace -2 with -10 and so on. If you are not certain when disk usage happened, skip this!

To find disk usage of each folder in problematic space, do next!

server#du . -h -s *
59G    .
58G    data
50M     apache-tomcat-7.0.32

This will list usage of each folder in /opt, each file in /opt and total usage of opt. Go inside biggest folder and continue search for that big disk usage!

No comments: