find -exec question

Richard Hector richard at walnut.gen.nz
Sat May 17 04:08:49 UTC 2014


On 12/05/14 09:46, R Kimber wrote:
> On Sun, 11 May 2014 14:29:16 -0500
> C de-Avillez wrote:
> 
>> You may be hitting the fact that sort output will depend on locale
>> setup.
> 
> Can you explain this more?  If I do
> 
> for files in *; do echo $files; done
> 
> I get the directories listed in alphabetical order.  Also 'ls' gives
> alphabetic output.  I don't see why 'find' should produce output in a
> different order.

I don't think find does any sorting; it just scans through in the order
files are listed in the directory. ls and '*' do sort, so you don't see
that order - unless you use "ls -U".

If you want the results sorted, you'll have to do that outside of find,
using 'sort' or similar. But then, you'll have to work out exactly what
you want - probably sorting at each level in turn, rather than sorting
the filenames alone? That might get more complicated ...

Richard





More information about the ubuntu-users mailing list