Date: Tue, 27 May 2003 10:35:04 -0400 From: "Joseph Gleason" <clash@tasam.com> To: "Joachim Dagerot" <joachim@dagerot.nu>, <freebsd-questions@freebsd.org> Subject: Re: shell programming - how to write a script that renames files aftertheir last moddate? Message-ID: <005001c3245d$2ad0c7b0$08695f0a@frigate> References: <200305271318.h4RDIDs21928@thunder.trej.net>
next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. ------=_NextPart_000_004D_01C3243B.A2B531C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit If someone knows how to extract the unix time that a file was modified in shell, it is easy. I usually write a C++ program for that step. for file in *.jpg do MODTIME="`getmodtime $file`" NEWNAME="`echo -n "$file"|cut -d "." -f 1`_`date -r $MODTIME +%Y%m%d%H%M%S`.jpg" mv $file $NEWNAME done Not sure if this code is right, but the -r for the date makes it use the next argument (which should be seconds from epoch) as the time. The +% stuff is formating how you want the output. I have attached the code for getmodtime. Does anyone know how to get the modification time_t from a file in shell script? There is probably some command to do it that I don't know about. ----- Original Message ----- From: "Joachim Dagerot" <joachim@dagerot.nu> To: <freebsd-questions@freebsd.org> Sent: 27 May, 2003 09:18 Subject: shell programming - how to write a script that renames files aftertheir last moddate? > This is certainly not freeBSD specific and probably I'm annoying > someone for being off-topic but please be patient and hint me on where > to find good resources in shell-programming. > > > > I could use some help in writing a script that renames all files in a > directory tree to the files last modified date, example usage: > > > daterename "Img_" *.jpg > > the command above will rename all *.jpg files to "Imag_<date>".jpg > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" > ------=_NextPart_000_004D_01C3243B.A2B531C0 Content-Type: application/octet-stream; name="getmodtime.cpp" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="getmodtime.cpp" #include <sys/types.h>=0A= #include <sys/stat.h>=0A= #include <iostream>=0A= =0A= =0A= int main(int args, char* argv[])=0A= {=0A= struct stat FileInfo;=0A= stat(argv[1],&FileInfo);=0A= =0A= cout << FileInfo.st_mtime << endl;=0A= =0A= }=0A= ------=_NextPart_000_004D_01C3243B.A2B531C0--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?005001c3245d$2ad0c7b0$08695f0a>