From owner-freebsd-questions@FreeBSD.ORG Tue May 27 07:34:39 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BEB0937B401 for ; Tue, 27 May 2003 07:34:39 -0700 (PDT) Received: from zogbe.tasam.com (63-165-178-196.uterr.blacksburg.ntc-com.net [63.165.178.196]) by mx1.FreeBSD.org (Postfix) with ESMTP id DE63143F85 for ; Tue, 27 May 2003 07:34:38 -0700 (PDT) (envelope-from clash@tasam.com) Received: from frigate (root@zogbe.tasam.com [10.95.95.5] (may be forged)) by zogbe.tasam.com (8.12.9/8.12.9) with SMTP id h4REYYlW097506; Tue, 27 May 2003 10:34:35 -0400 (EDT) Message-ID: <005001c3245d$2ad0c7b0$08695f0a@frigate> From: "Joseph Gleason" To: "Joachim Dagerot" , References: <200305271318.h4RDIDs21928@thunder.trej.net> Date: Tue, 27 May 2003 10:35:04 -0400 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_004D_01C3243B.A2B531C0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Subject: Re: shell programming - how to write a script that renames files aftertheir last moddate? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 May 2003 14:34:40 -0000 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" To: 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_".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 =0A= #include =0A= #include =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--