Link to home
Start Free TrialLog in
Avatar of mindlessacts
mindlessactsFlag for United States of America

asked on

Deleting all logs on all servers quickly

Hello I need to delete all log files in my /home/users folder

I need to go down into ever directory and delete all .log files.

Also if I could use rsync to do it so that I can do this on all my servers that would be great (the server directories are different for some users, and completely different on each server box)

How would I do this?

Thanks, Brad

Avatar of Nick Upson
Nick Upson
Flag of United Kingdom of Great Britain and Northern Ireland image

find /home/users -name *.log -exec rm -f {}\;

I don't think you can this with rsync because of all the differences between servers
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mindlessacts

ASKER

What if I wanted to first make a backup of all those log files. And compress it?

I tried: find /home/users -name *.log -exec tar -cz -f logs.tgz{}\;

find: missing argument to `-exec'

However it did not work

Thanks, Brad
the find command works on each file seperately, you would now need something more like this

for file in `find /home/users -name *.log `
do
  tar -A backup.tar $file
  rm -f $file
done

compress backup.tar
Avatar of Tintin
Tintin

or as a two step process

find /home/users -type f -name "*.log" | tar czvf /tmp/logs.tgz
find /home/users -type f -name "*.log" | xargs rm -f
I tried:

find /home/user -type f -name "*.log" | tar czvf /home/logs.tgz

and it returned;

tar: Cowardly refusing to create an empty archive
Try `tar --help' for more information.

However there are several .log files in the directory
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent

Thank you very much for all the help.