|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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? Thanks. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On May 27, 12:02 am, osi...@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? > Thanks. No. The first command says recursively descend "." and list files named 'old' AND that are newer than 'new'. There are none. The second swaps old and new and thus lists "new". |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
osiris@abydos.kmt wrote:
> find (in the current directory tree) if the file with -name "old" > is -newer than the file named "new"" find operates recursively. So if in any subdirectory a file with name "old"/"new" is found this may also be printed. If you just want to compare the two files you can compare them directly with find: find old -prune -newer new find new -prune -newer old No need for ".". -prune is needed if old/new is a directory instead of a regular file. See example 6 in http://www.opengroup.org/onlinepubs/...l#tag_04_55_17 Some shells also offer the test primaries -nt/-ot. But this is a nonstandard extension, see http://www.opengroup.org/onlinepubs/...#tag_04_140_18 -- Daniel |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Sun, 27 May 2007 04:02:16 GMT, osiris@abydos.kmt
<osiris@abydos.kmt> wrote: > > > I thought of a way to compare modification dates > of two files in order to determine which is newer. > Another way to compare file dates is ls -t old new The newest file is listed first, or last if you change -t to -tr. -- Honk if you hate bumper stickers that say "Honk if ..." |
|
![]() |
| Outils de la discussion | |
|
|