Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
1  
What is your exact find command? –  Andrew Oct 2 '12 at 5:44
add comment

2 Answers

up vote 1 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
1  
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
add comment

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
add comment

Your Answer

 
discard

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.