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

I have two directories (~/www/ and ~/client-sites/) that contain a bunch of sites, each with access.log and error.log files.

What is the easiest way to find all of these files and empty their contents? They grow quickly so I'd like to clear out logs once every month or so.

share|improve this question
Why? You could just use logrotate. – Michael Hampton Jan 23 '13 at 22:47
No need to reinvent the wheel. Use logrotate. Custom tools will only confuse your coworkers and future sysadmins at your workplace. – Stefan Lasiewski Jan 25 '13 at 19:13
up vote 9 down vote accepted

Install logrotate (Windows see

yum install logrotate
# Debian/Ubuntu
apt-get install logrotate

Create/Edit /etc/logrotate.d/httpd, Example is taken from CentOS, adjustment is needed for other Distros.

/var/log/httpd/*_log {
    rotate 5
    create 640 root adm
        /etc/init.d/httpd reload > /dev/null
share|improve this answer

Toa ctually do what you requested

find ~/www/ and ~/client-sites/ \( -name 'access.log' -o -name 'error.log' \) \
    -exec sh -c '> "$1"' -- {} \;

Which will truncate each file matching either file name in any sub directories to 0 bytes.

share|improve this answer
Instead of running sh, truncate (part of coreutils) could be used, i.e. -exec truncate --size 0 {} \; or -exec truncate --size 0 {} \+ – Cristian Ciupitu Jan 29 '13 at 13:13
Thanks for answering, this worked great! :-) – Mitch Feb 6 '13 at 4:06

The apache web server comes with a utility called rotatelogs, which can be used to control log files.

Yes, hardly any distros use it.
No, they don't know better - they're just ignorant.

share|improve this answer

Your Answer


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

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