using find
to find all files you want to rename and running an exec
script:
`
find /main/rel -name file.log -exec mv '{}' '{}.OLD' \;
this will run the mv
cmd on all found files, the {}
(escaped so the shell doesn't do weird things) will be replaced by the filename.
this allows you to easily add extra characters to the original filename (e.g. append .OLD
).
anyhow, checkout logrotate
, which is a tool that was created for the job you want to do.
it not only rotates logfiles for you (e.g. rename logfile
to logfile.0
; but before it moves logfiles.0
to logfile.1
; compress older logfiles so they don't take up much space; delete very old logfiles) but also notifies the daemon that writes the logfile that it probably needs to reopen the new one (else you might rename your logfile
to foobar.bak
, only to discover that the server keeps appending to foobar.bak
...)