How to Find the Largest Files and Folders in Linux

If you work with Linux long enough you will probably run out of space on a box somewhere. More often than not it always seems to happen on a production machine and you have a very upset customer. No worry though, the problem is trivial to fix with the right set of commands. There are also multiple ways to do the task, thanks to Linux.

On all of these commands I will work with the var directory, that seems to be the most common one I am working with.

1) DU

DU stands for drive usage. Of course it only makes sense to sort by size. We will take only the top 10 listings for a better visual. As you will notice this is recursive and shows the usage in a more hierarchical format.

2598612 /var
2486740 /var/lib
2350520 /var/lib/mysql
118580  /var/lib/mysql/MyVideos107
103380  /var/lib/apt
103324  /var/lib/apt/lists
88112   /var/cache
65864   /var/cache/apt
49984   /var/lib/mysql/MyVideos99
44620   /var/lib/mysql/MyVideos93

2) Find

I really like this result better because you can actually see which file is taking up the most space, but it really depends on what you are after. Most of the time this is my goto command.

1.9G    /var/lib/mysql/ibdata1
48M     /var/lib/mysql/ib_logfile1
48M     /var/lib/mysql/ib_logfile0
38M     /var/lib/apt/lists/
33M     /var/lib/apt/lists/
26M     /var/lib/apt/lists/
26M     /var/cache/apt/srcpkgcache.bin
26M     /var/cache/apt/pkgcache.bin
24M     /var/lib/mysql/MyMusic56/path.ibd
20M     /var/lib/mysql/MyVideos107/movie.ibd


I feel I just have to say something about NCDU. Sure you have to install it and it may not be available for all Linux environments, but it is pretty awesome and worth mentioning.

For a Debian or Ubuntu system installation


For YUM based installations, there is a thread here on how to install

Usage is very easy to remember

ncdu 1.12 ~ Use the arrow keys to navigate, press ? for help
--- /var -----------------------------------------------------------------------
    2.4 GiB [##########] /lib
   86.1 MiB [          ] /cache
   17.2 MiB [          ] /log
    3.4 MiB [          ] /webmin
    1.7 MiB [          ] /backups
  596.0 KiB [          ] /tmp
  268.0 KiB [          ] /mail
   36.0 KiB [          ] /spool
   20.0 KiB [          ] /www
e   4.0 KiB [          ] /opt
e   4.0 KiB [          ] /local
@   0.0   B [          ]  lock
@   0.0   B [          ]  run

What I really like about NCDU is the arrow key navigation. You can easily go up and down directories to really narrow down on where the disk usage is. The only draw back is if you can use it for your Linux flavor.

So we have went over three different ways to find drive usage. If you can think of any other ways worthy of mention leave a comment below.

You may also like

Leave a Reply

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