How does find order results?

How does find order results?

Post by m.. » Tue, 21 Mar 2000 04:00:00



Hello,

I am writing a script file that uses the following find command line:

find ${DPATH} -name 'log????.21' -mtime 1|tr "\n" " "|read CURLOG PRELOG

This will find two files that have been modified in the last 24hrs.

My question is, in what order will it list those two files?

I am assuming that it will report the most recently modified file last.

In other words, say the 1st file is closed at 3:00 and the 2nd file is
closed at 5:00.  It should then list the files in that order - 1st, 2nd.

While testing this, I could swear that our development system listed
them the other way around.  When I ran the script on our production
box, it was just opposite (both are AIX 4.2.1).

I can't find and documentation that clears this up.

Thanks,
Mike Merriman

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

How does find order results?

Post by Ken Pizzi » Wed, 22 Mar 2000 04:00:00



>I am writing a script file that uses the following find command line:
>find ${DPATH} -name 'log????.21' -mtime 1|tr "\n" " "|read CURLOG PRELOG
>This will find two files that have been modified in the last 24hrs.
>My question is, in what order will it list those two files?
>I am assuming that it will report the most recently modified file last.

Nope.  It will list the files in the order that it happens to
come across them as it traverses the directory tree.  The
sequence by which find visits files is based on a simple
unsorted iteration through each of the directory entries of each
directory in the tree.  Within a directory the ordering is
officially indeterminate, though most filesystem implementations
will use an algorithm along the following lines: a new filename
is added to the first available space within the on-disk
directory structure; if no deletes or renames ever happen in a
particular directory then all of its directory entries will be
in creation-time order, but if a delete happens a hole will be
created which the next file creation will fill that hole without
any regard for any kind of sort ordering.

You didn't state what shell you are using, but because you are
reading variables at the end of a pipeline I'll assume you're
using ksh.  Try this:
  find ${DPATH} -name 'log????.21' -mtime 1 | { read CURLOG; read PRELOG; }
  [[ $CURLOG -nt $PRELOG ]] || { tmp=$CURLOG; CURLOG=$PRELOG; PRELOG=$tmp; }

                --Ken Pizzini

 
 
 

How does find order results?

Post by Kurt J. Lanz » Wed, 22 Mar 2000 04:00:00



> Hello,

> I am writing a script file that uses the following find command line:

> find ${DPATH} -name 'log????.21' -mtime 1|tr "\n" " "|read CURLOG PRELOG

> This will find two files that have been modified in the last 24hrs.

> My question is, in what order will it list those two files?

> I am assuming that it will report the most recently modified file last.

> In other words, say the 1st file is closed at 3:00 and the 2nd file is
> closed at 5:00.  It should then list the files in that order - 1st, 2nd.

> While testing this, I could swear that our development system listed
> them the other way around.  When I ran the script on our production
> box, it was just opposite (both are AIX 4.2.1).

> I can't find and documentation that clears this up.

I suspect that "find" will list them in the order they
exist in the directory. Which is probably the order they
were originally placed in the directory, which may or
may not be the order they were "created".
 
 
 

How does find order results?

Post by bmar.. » Wed, 22 Mar 2000 04:00:00



   >Hello,
   >I am writing a script file that uses the following find command
   >line:
   >find ${DPATH} -name 'log????.21' -mtime 1|tr "\n" " "|read CURLOG
   >PRELOG
   >This will find two files that have been modified in the last 24hrs.
   >My question is, in what order will it list those two files?
   >I am assuming that it will report the most recently modified file
   >last.
   >In other words, say the 1st file is closed at 3:00 and the 2nd file
   >is closed at 5:00.  It should then list the files in that order -
   >1st, 2nd.
   >While testing this, I could swear that our development system listed
   >them the other way around.  When I ran the script on our production
   >box, it was just opposite (both are AIX 4.2.1).
   >I can't find and documentation that clears this up.

Find does not sort its output.  Two files in the same directory will appear
in the order that their names are stored.

Net-Tamer V 1.08X - Test Drive

 
 
 

How does find order results?

Post by m.. » Wed, 22 Mar 2000 04:00:00


Thanks, that explains what I was seeing...

Wouldn't this also work...

ls -1t `find ${DPATH} -name "log????.21" -mtime 1` | { read CURLOG;
read PRELOG; }

Thanks again,
Mike Merriman




> >I am writing a script file that uses the following find command line:
> >find ${DPATH} -name 'log????.21' -mtime 1|tr "\n" " "|read CURLOG PRELOG
> >This will find two files that have been modified in the last 24hrs.
> >My question is, in what order will it list those two files?
> >I am assuming that it will report the most recently modified file last.

> Nope. It will list the files in the order that it happens to
> come across them as it traverses the directory tree. The
> sequence by which find visits files is based on a simple
> unsorted iteration through each of the directory entries of each
> directory in the tree. Within a directory the ordering is
> officially indeterminate, though most filesystem implementations
> will use an algorithm along the following lines: a new filename
> is added to the first available space within the on-disk
> directory structure; if no deletes or renames ever happen in a
> particular directory then all of its directory entries will be
> in creation-time order, but if a delete happens a hole will be
> created which the next file creation will fill that hole without
> any regard for any kind of sort ordering.

> You didn't state what shell you are using, but because you are
> reading variables at the end of a pipeline I'll assume you're
> using ksh. Try this:
> find ${DPATH} -name 'log????.21' -mtime 1 | { read CURLOG; read PRELOG; }
> [[ $CURLOG -nt $PRELOG ]] || { tmp=$CURLOG; CURLOG=$PRELOG; PRELOG=$tmp; }

> --Ken Pizzini

Sent via Deja.com http://www.deja.com/
Before you buy.
 
 
 

How does find order results?

Post by Ken Pizzi » Thu, 23 Mar 2000 04:00:00



>> find ${DPATH} -name 'log????.21' -mtime 1 | { read CURLOG; read PRELOG; }
>> [[ $CURLOG -nt $PRELOG ]] || { tmp=$CURLOG; CURLOG=$PRELOG; PRELOG=$tmp; }
>Wouldn't this also work...

>ls -1t `find ${DPATH} -name "log????.21" -mtime 1` | { read CURLOG;
>read PRELOG; }

Sure, though I'd put that command-substitution in double-quotes
to protect against the possibility of a matching path containing
a space.

                --Ken Pizzini

 
 
 

1. How to obtain the result of the order find on several columns

Hi,

When I redirect the result of the order find on a file named " logplus  ", I
obtain the result there on only one column (200 file names).  How  to make
to obtain the result of the order find on several columns in  my file "
logplus "?

Here the syntax of the order which I launched:  find / home - name ' * o'
print > logplus

Thanks,

GUY

2. Formating a new partition

3. Order of globbing result in bash, bug or feature?

4. Break this enigma ciphertext.

5. find on my cd-rom doesn't work, but find on dos does

6. SLS for amiga

7. Performance tests done on sd show better results on non-smp m/c

8. Help! Killed mouse!

9. Total store order and partial store order

10. Order, Order!

11. Apache "Order Allow,Deny" vs "Order Mutual-failure"?

12. Need Portable Way to Find Byte Order

13. How does find(1) decide search order of directories?