Welcome to WebmasterWorld Guest from 23.22.46.195

Forum Moderators: bakedjake

Shell script to rename files by date

looking for advice

   
2:41 pm on Feb 13, 2003 (gmt 0)

10+ Year Member



Hi all,

My web host puts out logfiles on a daily basis, except they appear to be named:

log-(random10digitNumber).gz

I'm wondering if anybody can think of a shell script I can run that would rename them something like this:

log-(fileCreationDate).gz

I can figure out how to loop through the files, and rename them with a shell script, but I especially don't know how to access the fileCreationDate to put into the file name.

Any ideas? Thanks in advance...

Cameron

3:34 pm on Feb 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The following very ugly script (which only echos file names) might get you started:

% foreach i ( * )
foreach? echo log-`ls -l $i awk '{printf "%s-%s", $6, $7}'`
foreach? end

There has to be a better way, but a quick look at the man pages for tcsh does not reveal a way of getting the mod date into a variable.

Looks like a candidate for a perl rather than shell script :)

4:04 pm on Feb 13, 2003 (gmt 0)

10+ Year Member



Thanks Mohamed_E,

I'll do a check to see if that works....

Perl would be a good idea, but I don't know it at all, but you did give me an idea. I could totally do this with PHP, and PHP has just introduced a command line interface version....so...hmmm..

Cameron

6:11 pm on Feb 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



log-(random10digitNumber).gz

I seriously doubt this is random. In fact, I'd be quite suprised if it were anything other than the number of seconds since the beginning of the epoch - AKA a unix timestamp. If you're going to attack it with PHP, try splitting out the number and running it through strftime();

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month