Skip to content

Instantly share code, notes, and snippets.

@benders
Created March 26, 2011 05:31
Show Gist options
  • Save benders/888048 to your computer and use it in GitHub Desktop.
Save benders/888048 to your computer and use it in GitHub Desktop.
Rename logs from logrotate style foo.1.gz to date style foo.2011-03-25.gz
#!/bin/bash
ls -l --time-style="+%Y-%m-%d" *.?.gz | awk '{ print $7,$6 }' | \
while read line; do
set -- $line
original=$1
datestamp=$2
filebase=`echo $original | rev | cut -f3- -d. | rev`
/bin/mv -vu $original $filebase.$datestamp.gz
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment