Linux – How does this directory use so much space

disk-usagefilesystemslinux

Unix is not my native language and I'm getting confused by their concept of filesystems.

When I look at my free space I see:

/$ df -kh
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  7.1G  397M  95% /
none                  3.7G  120K  3.7G   1% /dev
none                  3.7G  4.0K  3.7G   1% /dev/shm
none                  3.7G   48K  3.7G   1% /var/run
none                  3.7G     0  3.7G   0% /var/lock
/dev/xvdf             100G   19G   82G  19% /db
/dev/xvdg             100G   15G   86G  15% /images
/dev/xvdb             414G  199M  393G   1% /mnt

To me this means all files and directories under /db is on filesystem xvdf, everything under /images is on xvdg and everything under /mnt is on xvdb. Everything else is on xvda1.

However, xvda1 has only 7.9G of space. So why does

/$ sudo du -sh var
25G     var

show me that /var is taking up 25G? I thought at first that maybe it's counting the contents at the destinations of symbolic links but I know a few directories down there's a symbolic link to the /images directory and that's got 86G of content so var should be >86G if symbolic links are followed.

So how can /var take up 25G on a drive that has only 7.9G?

btw, this is an ubuntu instance running in amazon's EC2, if that's significant.

Best Answer

This will give you proper answer of your trouble.

du -ch --max-depth=1 -x /var

-x will show only data usage of one file-system so skipping other filesystem's content from /var directory

--max-depth=1 will give data usage of only first level e.g. /var/a /var/b and so on

Related Question