Discussion: the newer of 2 files
Afficher un message
Vieux 27/05/2007, 07h45   #3
Jeroen van Nieuwenhuizen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: the newer of 2 files

On Sun, 27 May 2007 04:02:16 GMT
somebody claiming to be osiris@abydos.kmt wrote:
> I thought of a way to compare modification dates
> of two files in order to determine which is newer.
> The man page does not explain this.
> However, I'm not sure whether this is accurate:
>
> $ touch old
> $ touch new
> $ find . -name old -newer new
><no output>
> $ find . -name new -newer old
> ./new
>
> I would have expected the first command to tell me
> that the file named "new" is newer
> yet I suspect that because "old" is not newer, there is no output.
> So I should interpret this comparison in the first example as:
>
> find (in the current directory tree) if the file with -name "old"
> is -newer than the file named "new""
>
> is that correct?


Yes, that sounds correct to me. But you can also use the -nt or -ot option of
the test command instead of find if you want to find out which file is
newer. Something like
[ new -nt old ] && echo newer
would than output newer in your case.

Regards,

Jeroen.

--
ir. Jeroen van Nieuwenhuizen
Email: jnieuwen [at] jeroen [dot] se
I know I'm not perfect but I can smile
  Réponse avec citation
 
Page generated in 0,08862 seconds with 9 queries