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.

Continue Reading

Three Different Ways to Reboot a Linux System

How do I reboot my Linux system? When you are a new to the Linux operating system sometimes what should be painfully obvious is not so apparent. Luckily there is more than one way to reboot your Linux box. We will go over the init, reboot and shutdown commands. All methods vary greatly in syntax so once one seems memorable, it is probably better to stick to that one. I have been using Linux a very long time so we will start off with the one I learned first.

Init 6

This method is actually probably the least used but also the safest. When you change the init level to 6, there is a clean up process that is done. This differs from a reboot command which is more like hitting the reset button. Either use sudo or log in as root.



There is a bit of controversy on the reboot command and it if actually shuts down processes in a graceful manner. It does seem to at least cleanly dismount the file system. What reboot does have going for it though, at least it is easy to remember though, because what you want to do is reboot right? So there is that. If you are clear across the globe and remoted it maybe reboot is the command for you. If a program hangs we may get stuck if you do not have a technology like PDU or iDrac available.



If you are running a multi user system then you may need to warn your users. With the shutdown command you can send a notice and delay the restart to a time you designate.


The last value is in minutes, you can actually use the word now which is an immediate reboot. You can also use a format and do a predesignated time like this. This would reboot at 11pm.

Continue Reading