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

Is there an easy step to clear contents of all ".log" file using find command.

Currently i am using "echo -n > filename.log" i have tried echo -n > /var/application-logs/*.log but it is not working..

is there a better way to clear contents of multiple files?

share|improve this question
What is your exact find command? – Andrew Oct 2 '12 at 5:44
up vote 2 down vote accepted

To clear everything find /var/application-logs -type f -name "*.log" finds, use this:

find /var/application-logs -type f -name "*.log" -exec tee {} \; </dev/null

If your version of find supports it, use + instead of \; to use a single run of tee for all of the files. Alternately, if a shell glob is sufficient:

tee /var/application-logs/*.log </dev/null
share|improve this answer
POSIX stipulates that find supports {} +; I don't know of any that don't. – adaptr Oct 2 '12 at 9:59
@adaptr: I could've sworn I saw one that didn't support + recently, but maybe I'm imagining it. You're right, though, it is in the Posix standard. – Gordon Davisson Oct 2 '12 at 22:14

If you want to stop your logs from growing, use logrotate. You should not be blindly wiping logs just because they are full. There are good HOWTOs available for many different distros.

Alternatively, consider using a syslog server such as rsyslog or syslog-ng.

share|improve this answer
i am using logrotate,,,this is a special case where i want to perform benchmark on application,which i need to monitor logs.So it will be convinient to remove all logs relating to that.. – hariharan Oct 2 '12 at 5:25
@hariharan It would be worth updating your original question with this information so that your intent is clear. – Andrew Oct 2 '12 at 5:27
can u please check now...i have changed log location – hariharan Oct 2 '12 at 5:32

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.