homepage Welcome to WebmasterWorld Guest from 54.211.95.201
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
Shell script to rename files by date
looking for advice
cbooth7575




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

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

 

Mohamed_E




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

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 :)

cbooth7575




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

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

dingman




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

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();

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved