1

I'm looking for a way to batch rename almost 1,000 log files created by an Eggdrop bot. A few years ago, I had to setup my bot from scratch, and neglected to set the log format properly, so all of these files now have the format:

channelname.log.%d%b%Y (channelname.log.14Jan2014)

I want to rename all those files to match all my old log files, which are in the format of:

channelname.log.%Y%m%d (channelname.log.20140101)

I've already made the change in my eggdrop.conf file, but I would like to rename all the newer log files to match the format of the old ones.

This is on a Linux shell, so some sort of bash command would be ideal. Thanks!

4

1 回答 1

2
find . -type f -name '*.log.*[^0-9-]*' -print0 | while read -d '' -r logfile; do
    mv "${logfile}"  "${logfile/.log.*/.log.`date -d ${logfile#*.log.} +%Y-%m-%d`}"
done

Assuming it's in a locale date knows how to handle.

于 2014-11-18T20:50:10.597 回答