for i in logfilename.*.gzThe argument -r to date(1) command tells it to use the last modification date (mtime) of a file given as the argument to the option. Note that it is also possible to use stat(1) command instead of date(1).
do
mv -i $i logfilename.`date -r $i +%Y%m%d`.gz
done
Random notes of what's on my mind. Additional materials you'll find on my homepage.
Saturday, February 28, 2015
Short Tip: Renaming log files to include date...
I had a bunch of a log files in the format logfilename.N.gz, but I wanted to rename them into logfilename.YYYYMMDD.gz where YYYYMMDD is a date when the file was last modified. I did it using the following for loop:
Subscribe to:
Post Comments (Atom)
About Me
- Stjepan Groš (sgros)
- scientist, consultant, security specialist, networking guy, system administrator, philosopher ;)
No comments:
Post a Comment