[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: find - output order



Alex Samad wrote:
> Hi
> 
> does find out put files in any sort order ?
> 
> for example 
> 
> for x in $(seq -w 00 99); do touch $x ii$x aa$x; done && find ii* [0-9]*
> aa*
> 
> is the output guaranteed to be in sort order, i.e. ii* files first and
> sorted and then [0-9]* files next and sorted and then aa* files and
> sorted
> 
> 
> Alex
> 

Hi, Alex,

The short answer is "no".

A bit longer ;) ...

The 'find' command reads the directory data (filename/inode ...) in the
order it was created.  It prints the data as found.

Actually, 'ls' reads the same as 'find', but 'ls' does an internal sort
before printing it.  You can use '-f' or '-U' with 'ls' to "not sort" or
to "list entries in directory order" (quotes from the 'ls' man page).

And more ;) to see just what this means:

Run these commands, then compare the output:

ls -U > /tmp/ls-U.txt

find . -maxdepth 1|sed -e '/^\.\/\./d' -e 's/^\.\///'>/tmp/find_out.txt

You need to massage the 'find' output to 1) eliminate the 'dot' files;
2) to remove the leading './' 'find' prepends to create the path name.

Do a diff between the files.  The only difference you'll find is the
file "..", which the 'ls' command keeps.  Since 'find' is recursive, it
has to ignore the '..', else it would climb up the tree, not just down,
and infinitely.

-- 
Bob McGowan

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


Reply to: