I have 2 different machines - one running RHEL7 and one running CentOS-7.5.

find --version reports version 4.5.11 on each.

I've created the following dierectory structure on each.


When I run find -name some-file on the RHEL7 machine, I get output which matches the above.

But when I run find on my CentOS-7.5 machine, my results list in reversed order.

Why is this?


The order in which find traverses the directory structures of its search paths is probably the order in which the readdir() library function returns the directory entries in. These entries are not further ordered by find and will therefore likely depend on the order in which the directory entries were created in the filesystem, and maybe even on the order in which other files and directories on the same partition were created and deleted, depending on the filesystem implementation.

You will get the same ordering in the output of ls -f.

  • The files were created in the same order on both machines, and each machine is using the ext4 filesystem. – DeepDeadpool Mar 6 at 21:29
  • 1
    @DeepDeadpool To get the same order on both systems would be not quite as unexpected as getting the exact same inode numbers for these files and directories on both systems, but close. – Kusalananda Mar 6 at 21:34
  • @DeepDeadpool BTW, you can see the inode numbers in the output of ls -i. – Kusalananda Mar 6 at 22:11
  • 1
    Some find implementations, under some circumstances at least would order the list of files by inode as an optimisation (to minimize disk head seeks when looking at stat info in the inode table). – Stéphane Chazelas Mar 6 at 22:42
  • I'll investigate that. I think you're right because I ran my tests a few more times and sometimes the order is not consistent on the RHEL machine. By that I mean that the output listing may sometimes be independent of creation order. – DeepDeadpool Mar 6 at 23:38

According to the man page for readdir()

The order in which filenames are read by successive calls to readdir() depends on the filesystem implementation; it is unlikely that the names will be sorted in any fashion.

This means that the order in which you get the response is really depending on the filesystem, and you can’t expect any order. Most likely you are getting the order in which the entries are stored in the directory structure, and that is not going to be identical from one system to the next because of how the disk is laid out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.