On 08:53 13 Mar 2003, Anthony E. Greene <[EMAIL PROTECTED]> wrote:
| On 13-Mar-2003/12:02 +0000, Zhi Cheng Wang <[EMAIL PROTECTED]> wrote:
| >thanks for the message. but i do not want to add current time, the time
| >stamp of the file is needed
| 
| There was a thread about that on this list a few months ago. There is no
| easy solution that will work across multiple versions of Linux.

Given perl, there probably is. Almost every system has perl.

| On my
| RH72 system, this works:
| 
| cd $targetdir
| for datafile in `ls -1`; do
|   modifydate=`ls --full-time $datafile | cut -c 44-62`
|   formatteddate=`date -d "$modifydate" +%Y-%m-%d`
|   mv "$datafile" "datafile.$formatteddate"
| done
| 
| You'll have to modify the ls command and the columns of characters to cut
| depending on the version of ls that the system uses.

This:

perl -e '(@s=stat($ARGV[0])) || die;
         @tm=localtime($s[9]);
         
printf("%04d-%02d-%02d-%02d:%02d:%02d\n",$tm[5]+1900,$tm[4]+1,$tm[3],$tm[2],$tm[1],$tm[0]);'
 filename

Transcribe the file's mtime in an ISO style string. Hack to suit.
Put it in a script called "mtime2iso" and use in Tony's script:

        cd $targetdir
        for datafile in *; do
          formatteddate=`mtime2iso "$datafile"`
          mv "$datafile" "datafile.$formatteddate"
        done

Cheers,
-- 
Cameron Simpson, DoD#743        [EMAIL PROTECTED]    http://www.zip.com.au/~cs/

Copies of ACM publications are filling library self space so rapidly that
shelf boundaries will soon be expanding faster that the speed of light.
But Special Relativity is not violated, as no information is being propagated.
        - Howard E. Motteler, <[EMAIL PROTECTED]>



-- 
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to