Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The disk is nearly full,how to investigate which files are occupying most space?


I found most space are taken by mysql bin log:

/var/lib/mysql/jiaoyou-slow.log: 53M
/var/lib/mysql/mysql-bin.000005: 68M
/var/lib/mysql/mysql-bin.000003: 1.1G
/var/lib/mysql/mysql-bin.000007: 34M
/var/lib/mysql/mysql-bin.000004: 225M

Are these files safe to delete?

share|improve this question

migrated from Nov 6 '09 at 23:46

This question came from our site for professional and enthusiast programmers.

Don't touch those logs. There is a strong possibility that those log files can be truncated by merely performing a database backup. I'm not a MySQL expert, but you should at least look into it. – djangofan Jun 30 '11 at 16:39

Something like this should do the trick for you:

find / -type f -size +20000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

This looks for any file under / (root) that is roughly over 20mbs in size. You may need to adjust the $9/$5 variables but in most cases you won't have to. I also recommend changing / to /var/log/ if you simply want to look under your default log folder.

share|improve this answer
It only output file size but not the file names... – Mask Nov 6 '09 at 4:22
As I said, you may need to fidget with the variables. Try changing $9 to $8 and so forth. On my OSX system, that outputs file names and sizes but it may be different on yours. – Bartek Nov 6 '09 at 4:25

If you are using a graphical environment, you could use something like Disk Usage Analyser (aka Baobab) that can produce a nice ringschart as shown below:

alt text

The command line is still your best weapon but I find it very handy. There are some alternatives here.

share|improve this answer
I'm using command line. – Mask Nov 6 '09 at 4:40

Its a good idea to use logrotate(8) to compress and remove old log files, so that some chatty daemon doesn't fill up the entire disk.

EDIT: Also, most logs will be located in /var/log. A simple ls -lh will list which ones are getting too big.

share|improve this answer

The du command, at a command-line, will tell you which directories/folders are occupying the most space. You can infer from this where the biggest files are.

$ du -h /

The -h tells du to list the sizes in 'human readable terms: kb, Mb, Gb, and so on.

If you try this as an ordinary user, you'll see error messages about directories you don't have permission to examine.

If you do it as root, there should be no error messages.

# du -h /

pipe the output through sort -n so that the last lines show the biggest directories (or reverse sort and use head).

# du -h | sort -n

Another approach would be to use find with options which specify 'find files bigger than a certain size' but this method requires some practice to get it right.

# find / -size +10M

will list files bigger than 10Mbyte

share|improve this answer
It's listing too much information.How to target the biggest files at once? – Mask Nov 6 '09 at 4:21

If you have reasonably-sized partitions, You should search for large files outside the log directory. Logs are unlikely to be your problem, they seldom reach more than 200 MiB on the average system.

You should refrain from deleting logs as long as you are not sure what you actually do. Many daemons react pretty erratic if their logfiles are gone suddenly - the results can be anything from no-longer-working services up to being unable to restart that particulary service.

You should be save if you remove the files under /var/log/* that are archived (e.g. have the ending .gz). Again, I doubt that actually solves your main problem (e.g. harddisk too full)

share|improve this answer

Top 25 directories and/or files:

du -m / | sort -rn | head -25
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.