The script below allows to rotate file (e.g.: logfiles). By default, the length of rotation is 5. It means that this script rotates some file no more than for 5 times.
Let's consider the permanently growing file of some application named as
something.log
and we'd like to keep records in this file for the long time as much as possible. But for some reason this file is cleaning up periodically or a size of the file affects on the application's performance.
The recent records are available from the file
something.log
and the previously saved records are available under the name
something.log.1
, etc until the
something.log.5
. After the following rotation the content of the last file will be lost and replaced by the content of the previous file (
something.log.4
will be copied to the
something.log.5
) and the first file
something.log
will be copied to the
something.log.1
. At the same time the
something.log
will be truncated.
rotate something.log 10