bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: find bug?


From: Bob Proulx
Subject: Re: find bug?
Date: Thu, 12 Dec 2002 22:19:04 -0700
User-agent: Mutt/1.4i

Sam Halliday <address@hidden> [2002-12-13 01:43:56 +0000]:
> 
> im very sorry.. i didnt make myself entirely clear... by 'parsing' i
> mean, 'looks at and displays the file in a different order'. ls will
> always organise the files alphabetically (or whatever i tell it to), but
> find seems to not be consistent in the parsing 'order' of files on these
> 2 filesystems, ext3 and iso9660

Ah!  Now the "problem" is more clear.  The output order is different
between the two cases.  Can't compare the md5sums between the two
cases because of the different ordering.

> there are 2 files, "hd.md5sum" is the command
> find . -type f -exec md5sum '{}' ';'
> under an ext3 FS, and "cd.md5sum" is the same command under iso9660. a
> simple diff will show that the order of the files is different in each
> case... and in my case, this means i am unable to compare md5sum lists
> of 2 trees to see what has changed...

What you are seeing is normal behavior of the commands.  There is no
bug here.  But there is hopefully a solution to your problem.

A few points will clarify what is happen.

  As you mentioned 'ls' sorts the filenames when printing them by
  default as this is the normal desirable behavior for ls.

  The 'ls' command has an option to print the contents of the
  directory in "directory" order.  That is in the order that filenames
  are internally listed in the directory.  -U, --sort=none

  The 'find' command uses "directory" order.  If you want them sorted
  you need to sort them externally from find.

Because you are creating the md5sum file with 'find' you are getting
the listing in internal directory ordering.  This is not a bug but a
normal behavior of find.  It does not spend any time sorting the
filenames.  Normally this would be unneeded overhead.

The reason the directory order is different in different directories
is that the files were created in different orders in the different
directories.  As you create, rename, delete files the order will
change and be unique to each directory.  You can see the directory
order using 'ls -U'.  This is the same order that find uses.

  ls -U1

If you want your md5sum output to be in a particular order such as
sorted alphabetically then you need to guarantee that order yourself.
Try this command as an alternative to what you were doing.  This
should create the output in the same order each time.

  find . -type f -print0 | xargs -r0 md5sum | sort -k2

This sorts the output based upon the second field.  The second field
being the filename in your example.  This way all of the files will be
in a specific order and it should be possible to 'diff' and 'cmp'
them easily.

Please note that sort order depends upon your 'locale' setting which
is controlled by the environment variables LANG, and others LC_*.  If
it does not sort the way you want, a common problem, then check your
locale setting.  The order of your output looked like dictionary sort
ordering to me which leads me to suspect that you have LANG=en_US set.
In the case that this sort order is not what you want to see then
setting 'export LC_ALL=POSIX' is one way to guarantee a standard sort
order and will provide a traditional sort ordering.

> hope this report was more clear :D

Much, much better.

Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]