find -newer problem

Allan WIlkins devnull4spam@yahoo.co.uk
Tue Jun 28 09:56:00 GMT 2005


Iv done a bit more investigating. as I thought It might be something to 
do with the seconds (ls -l not displaying the seconds). The program t.c 
containing:

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

main(int argc,char *argv[])
{
    struct stat finfo;

    stat(argv[1],&finfo);
    printf("Access      : %s\n",ctime(&finfo.st_atime));
    printf("Modification: %s\n",ctime(&finfo.st_mtime));
    printf("Change      : %s\n",ctime(&finfo.st_ctime));
}

produces:

$ ./t XXX
Access      : Tue Jun 28 00:00:00 2005

Modification: Mon Jun 27 12:21:30 2005

Change      : Mon Jun 27 12:21:30 2005

$ ./t YYY
Access      : Tue Jun 28 00:00:00 2005

Modification: Mon Jun 27 12:21:30 2005

Change      : Mon Jun 27 12:21:30 2005

Exactly the same times so I wrote :

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

main(int argc,char *argv[])
{
    struct stat finfo1, finfo2;

    stat(argv[1],&finfo1);
    stat(argv[2],&finfo2);

    printf("%s: %s",argv[1],ctime(&finfo1.st_mtime));
    printf("%s: %s",argv[2],ctime(&finfo2.st_mtime));

    if (finfo1.st_mtime > finfo2.st_mtime){
        printf("File 1 newer than file 2\n",ctime(&finfo2.st_mtime));
    }
}

that produces:

$ ./fcmp XXX YYY
XXX: Mon Jun 27 12:21:30 2005
YYY: Mon Jun 27 12:21:30 2005
$ >a
$ >b
$ ./fcmp b a
b: Tue Jun 28 10:19:44 2005
a: Tue Jun 28 10:19:42 2005
File 1 newer than file 2

So I've now written newer.c to solve my problem

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

main(int argc,char *argv[])
{
    struct stat finfo1, finfo2;

    stat(argv[1],&finfo1);
    stat(argv[2],&finfo2);

    if (finfo1.st_mtime > finfo2.st_mtime){
        printf("%s\n",argv[1]);
    }
}

But I still don't really understand what find is doing.

Sorry about the cygcheck -s -v -r  :-(

Al


Igor Pechtchanski wrote:

>On Mon, 27 Jun 2005, Allan WIlkins wrote:
>
>  
>
>>I must apologise if this is an already known problem but I have been
>>unable to locate any reference to it in the mail archives.
>>
>>Executing a find using the -newer parameter returns files that appear to
>>be of the same age. e.g.
>>
>>$ find XXX -newer YYY
>>XXX
>>$ ls -l XXX YYY
>>-r--r--r--  1 allanw Domain Users 10291 Jun 27 10:38 XXX
>>-r--r--r--  1 allanw Domain Users  5865 Jun 27 10:38 YYY
>>$ ls -lu XXX YYY
>>-r--r--r--  1 allanw Domain Users 10291 Jun 27 00:00 XXX
>>-r--r--r--  1 allanw Domain Users  5865 Jun 27 00:00 YYY
>>$ ls -lc XXX YYY
>>-r--r--r--  1 allanw Domain Users 10291 Jun 27 12:21 XXX
>>-r--r--r--  1 allanw Domain Users  5865 Jun 27 12:21 YYY
>>
>>However:
>>$ touch AAA BBB
>>$ find AAA -newer BBB
>>$ ls -l AAA BBB
>>-rw-r--r--  1 allanw Domain Users 0 Jun 27 12:11 AAA
>>-rw-r--r--  1 allanw Domain Users 0 Jun 27 12:11 BBB
>>$ ls -lc AAA BBB
>>-rw-r--r--  1 allanw Domain Users 0 Jun 27 12:11 AAA
>>-rw-r--r--  1 allanw Domain Users 0 Jun 27 12:11 BBB
>>$ ls -lu AAA BBB
>>-rw-r--r--  1 allanw Domain Users 0 Jun 27 00:00 AAA
>>-rw-r--r--  1 allanw Domain Users 0 Jun 27 00:00 BBB
>>So if the files are created using touch the find does not return anything.
>>
>>I understand that ls -l displays the last modification time. Is the find
>>using the same date?
>>    
>>
>
>find *is* using the same date, but you may be running into filesystem
>granularity issues.  FAT, for example, stores dates with the granularity
>of 2 seconds.  You may also want to try "test AAA -nt BBB" and "test BBB
>-nt AAA", to see whether you get results that are consistent with "find".
>
>  
>
>>Thanks in advance
>>Al
>>
>>The output of a cygcheck -s -v -r > cygcheck.out follows
>>====================================================
>>[snip cygcheck output]
>>[snip *another* cygcheck output]
>>    
>>
>
>In the future, please *attach* the output of "cygcheck -svr" instead of
>including it in-line.  It cuts down on false positive matches in archive
>searches.
>
>HTH,
>	Igor
>  
>

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list