vote up 0 vote down star

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

EDIT

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?

flag
1  
belongs to superuser I think! – user14238 Nov 6 at 4:23
1  
Not sure if it belongs to superuser or serverfault, but not on stackoverflow for sure. – Pascal Thivent Nov 6 at 4:29

migrated from stackoverflow.com

6 Answers

vote up 3 vote down

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.

link|flag
It only output file size but not the file names... – Mask Nov 6 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 at 4:25
vote up 2 vote down

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.

link|flag
I'm using command line. – Mask Nov 6 at 4:40
vote up 0 vote down

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

link|flag
It's listing too much information.How to target the biggest files at once? – Mask Nov 6 at 4:21
vote up 0 vote down

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.

link|flag
vote up 0 vote down

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)

link|flag
vote up 0 vote down

Top 25 directories and/or files:

du -m / | sort -rn | head -25
link|flag

Your Answer

Get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.