Wednesday, January 18, 2012

How To Find The Largest Files On Your LAMP

My development server has been running low on space lately which is strange as I haven't been adding anything to it. I track my space usage with the df command.
df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda2            8.0G  4.8G  3.3G  60% /
tmpfs                 306M     0  306M   0% /lib/init/rw
udev                  286M   40K  286M   1% /dev
tmpfs                 306M     0  306M   0% /dev/shm
/dev/xvda1            130M   15M  109M  12% /mnt/boot
none                  306M     0  306M   0% /dev/shm

I've noticed the space on xvda2 slowly decreasing over the last few months. What could be causing it? None of my projects are that big, so how do I find what is responsible? Here's the command you'll need:
du -sm * | sort -nr | head -15
Just make sure you cd to the desired directory and this command will show you the 15 largest files and directories below your current directory. I started in my root ( cd / ) and followed the largest directory it found each time. In my case it was the ibdata1 file in MySQL that grew to over 2.6 Gb. I had been making lots of structure changes to my databases and it turns out that InnoDB does not reallocate space after you delete a table or modify something. After a few months my 300 Mb worth of databases were taking up almost 3 Gb.

No comments:

Post a Comment