I host about 200 websites and I have noticed that some got huge error_log files.

I would like to see which ones are consuming the most space so I can take a look on them and solve the error so they stop increasing in size so fast.

How can I find the biggest "error_log" files listed by location and size?

  • 2
    You're gonna have to give us more to go on than this. What have you tried? Where are you stuck? If the answers are 'Nothing' and 'At the beginning' then you're probably on the wrong website. – yoonix Jul 1 '14 at 0:05
  • du -kax /var/log | sort -n | tail -1000 can helps to check both directories and big files (sometimes there are directories full of small files). – Emmanuel Jul 2 '14 at 15:14

Have you tried something like this?

ls -lsR /var/log | sort -n | tail

Whether this works or not will depend on the structure of your log directories and the names of the files. This command will only tell you the file names of the ten largest files, not the directory paths.

Another option is something like this which finds all files over 1GB in size and prints the full paths to them:

find /var/log -size +1G -exec ls -lh {} +

Simply adjust the size to be slightly smaller than your largest log files.

Just in case you don't know where these error_log files are (judging by your other question, this might be the case), you can use locate error_log or find / -name error_log to find them. You can even add the -name error_log parameter to the above find command.


You can see a listing of all files in a directory and deeper using the du command.

An example of it's usage would be

# du -h
46K     ./R/win-library/3.0/colorspace/data
236K    ./R/win-library/3.0/colorspace/doc
63K     ./R/win-library/3.0/colorspace/help
12K     ./R/win-library/3.0/colorspace/html
61K     ./R/win-library/3.0/colorspace/libs/i386
57K     ./R/win-library/3.0/colorspace/libs/x64
118K    ./R/win-library/3.0/colorspace/libs
16K     ./R/win-library/3.0/colorspace/Meta
# ....

I'm late to the party here but everyone missed this "I host about 200 websites.."

Your question indicates you are looking for error_log files which I take to mean the php error logs. Your best bet is to use find and depending on your system and where the web root directories are located it should look something like this

find . -type f -name "error_log" -ls | sort -nr -k7

If you find some really big error logs, it would be advisable to look at them since they are probably full of php warnings that are relatively easy to correct and this would reduce the file sizes dramatically. (source: web hosting system administrator)



find /var/log -type f -exec du -h {} + | sort -h | tail

to find the 10 largest files in /var/log and to display there size in human readable units. Leave out or modify the | tail part to see more files.

Please note that the -h flag is a GNU extensions of sort and du and may therefore not work on all systems. Due due rounding to human units, the result might be not in the correct ordering. Alternatively, you can use

find /var/log -type f -exec du {} + | sort -n | tail

It displays the file sizes in block sizes (usually 1024 or 512 bytes).

  • Using -exec {} + instead of xargs would make it more reliable. Also note that all but one hard links would be excluded with some du implementations (including GNU's). You don't need -s if they're all regular files. du -h | sort -h | tail may not give you the biggest files, because the sizes are rounded before sorting. – Stéphane Chazelas Jul 2 '14 at 13:49
  • @StéphaneChazelas thanks, I included your comments in the answer. – jofel Jul 2 '14 at 13:56

Assuming that the error_log files are located somewhere under /var/log and that you are using the zsh shell, the following command would list the pathnames of the 10 largest of those files:

printf '%s\n' /var/log/**/error_log(.OL[1,10])

The glob qualifier (.OL[1,10]) will make sure that only regular files matches the pattern (.) and that the results are sorted in decreasing order of size (OL). The final [1,10] requests the first ten results of the glob.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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