Skip to content

Instantly share code, notes, and snippets.

@modsaid
Created October 21, 2014 17:50
Show Gist options
  • Save modsaid/38734f2ae1e832f267c1 to your computer and use it in GitHub Desktop.
Save modsaid/38734f2ae1e832f267c1 to your computer and use it in GitHub Desktop.
Rename hourly rotated web access logs (access.log.1, access.log.2) to include the timestamp for better management of the times
#!/bin/bash
# This script is made to rename default rotated access log files from access.log.1, access.log.2 and
# so on, to using timestamp instead of auto increment index (to be access.log.2014102009)
#
# USAGE:
# cd LOGS_DIR && ./access-logs-timestamp.sh
FILES=access.log*
for f in $FILES
do
newname="access.log.`date -r $f +'%Y%m%d%H'`"
echo "renaming $f to $newname"
mv $f $newname
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment