Find file sizes Linux / Unix

I had issues a few weeks ago with trying to find which files were being written to in a system where the disks were being filled up. I got this from one of my colleagues Roger (follow on twitter:@_rogerc).

The following command is based upon “du” a fuller explanation can be found here or by typing the following into a terminal on a Linux or Unix system (where available).

man du

So to the useful command I was given which was:

du -sh /* 2> /dev/null

So breaking this command down “du” is the actual command and after the – we have “s” that for a summarised output and “h” to tell it output in a human readable format. Currently this command is looking at the folders and files that exists from root. The “2> /dev/null” part of the command will hide errors from the command in this case it is generally stuff that you cant access with the user that you are logged in as. The following would give you the file sizes in the home directory:

du -sh /home/* 2> /dev/null

Basically you need to supply the file path with a /* at the end and it will list all the files and folders in that directory. You can then change the command to the interesting directory and repeat the command on that directory.

Hopefully this will help you find those pesky files that are filling up your system.

Leave a Reply

Post Navigation