LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   AIX (https://www.linuxquestions.org/questions/aix-43/)
-   -   Find command interpretation (https://www.linuxquestions.org/questions/aix-43/find-command-interpretation-4175456815/)

ilesterg 04-04-2013 04:22 AM

Find command interpretation
 
Hi all,

For IBM AIX, I would like to know what is the default 'sorting' for the files being displayed as a result of a 'find' command? For example i have the following command:

Code:

find . -type f -name "D2B.PAD*" |tail -1
I piped the find command with the tail command, with a purpose of returning the 'latest' file in the current folder. Please note that I did not use any 'mtime' parameter for the find command. So, with the command above, I do not have the guarantee that the latest file will be displayed.

However, I would like to know what is the default 'sorting' of the files being retrieved by the command. In other words, could I predict which files in the current directory will be retrieved first and last? I searched through IBM's website, and the closest that I could get is that the command 'recursively' searches the directory structure.

Kindly help me out.

NevemTeve 04-04-2013 05:01 AM

Don't expect anything, files can come in any order. (see also ls -U)

pan64 04-04-2013 06:16 AM

yes, the real order is more or less a random, not ordered sequence, just how these entries follow each other in the directory. It may change by several things like file creation, removal, modification ....
ls -U will give you this so called "directory order"

ilesterg 04-04-2013 10:46 PM

Thanks for the confirmation. Cheers!

Michael AM 04-18-2013 07:22 AM

random? I would have expected it to be the order in the directory. On AIX 6.1 it seems to be an alphabetical sort, and when find sees a directory it goes deeper, i.e., follows the tree, immediately.

Try od -d -c . to look at the directory view of the world. (Note: the first two bytes are the inode number (-d) the rest is the first 14 bytes of the filename (-c)

Code:

michael@x054:[/home/michael]od -d -c . | head -20
0000000    4096  11776      0      0      0      0      0      0
        020  \0  .  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000020      2  11822      0      0      0      0      0      0
        \0 002  .  .  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000040    4128  11891  29544      0      0      0      0      0
        020      .  s  s  h  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000060    4097  25697  29793      0      0      0      0      0
        020 001  d  a  t  a  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000100    4207  30770  12593  11885  30064      0      0      0
        020  o  x  2  1  1  .  m  u  p  \0  \0  \0  \0  \0  \0
0000120    4099  11894  26975  26729  29556  28530  30976      0
        020 003  .  v  i  _  h  i  s  t  o  r  y  \0  \0  \0
0000140    4160  25193  28160      0      0      0      0      0
        020  @  b  i  n  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000160    4100  11888  29295  26217  27749      0      0      0
        020 004  .  p  r  o  f  i  l  e  \0  \0  \0  \0  \0  \0
0000200    4192  11891  30050  30309  29299  26991  28160      0
        020  `  .  s  u  b  v  e  r  s  i  o  n  \0  \0  \0
0000220    4103  29549  26996  11891  25458  26992  29696      0
        020  \a  s  m  i  t  .  s  c  r  i  p  t  \0  \0  \0

find and ls -U are running alphabetically:
Code:

michael@x054:[/home/michael]ls -aUi | head
4096 .
2 ..
4216 .Xauthority
4105 .exrc
4100 .profile
4111 .rnd
4214 .sh_history
4128 .ssh
12290 .ssh2
4192 .subversion

Code:

michael@x054:[/home/michael]find . -ls | head
 4096    4 drwxr-xr-x 10 michael  felt          4096 Apr 17 19:47 .
 4216    1 -rw-------  1 michael  felt          400 Apr 16 22:22 ./.Xauthority
 4105    1 -rw-r--r--  1 root      system          37 Oct 29 11:59 ./.exrc
 4100    1 -rwx------  1 michael  staff          150 Feb 24 13:49 ./.profile
 4111    1 -rw-------  1 root      system        1024 Feb 28 15:32 ./.rnd
 4214  11 -rw-------  1 michael  felt        11148 Apr 18 12:20 ./.sh_history
 4128    4 drwx--x--x  2 michael  staff        4096 Apr 17 19:50 ./.ssh
 4129    2 -rw-r--r--  1 michael  system        1259 May  3  2005 ./.ssh/55WA.pub
 4130    1 -rw-r--r--  1 michael  staff          746 Apr  3  2003 ./.ssh/Michael AM Felt.pub
12291    2 -rw-r--r--  1 michael  felt          1246 Apr 17 19:45 ./.ssh/T430.pub


NevemTeve 04-18-2013 01:03 PM

True, in AIX 'ls -U' doesn't mean unsorted. Also, in AIX 6+ (unlike AIX 5) find does sort by filename.

ilesterg 04-19-2013 06:15 AM

Quote:

Originally Posted by NevemTeve (Post 4934181)
True, in AIX 'ls -U' doesn't mean unsorted. Also, in AIX 6+ (unlike AIX 5) find does sort by filename.

Hmmmmm. Do we have a documentation from IBM on this one? something that I could quote to my business guys?

NevemTeve 04-19-2013 07:19 AM

Well, the find manual I saw doesn't say anything about sorting the file-names, so it is only the result of my experiments: find in 5 doesn't sort, find in 6 does sort.

Michael AM 04-20-2013 04:16 AM

for your business guys i would focus on AIX 6.1, AIX 7.1 behavior. exception would be a script that depends on a particular sort versus do not care.

If i have time to load a partition with AIX 5, and i recall the question, I'll repeat my own suggestion above.

rknichols 04-20-2013 11:28 AM

The find program just processes names in whatever order they were obtained by a readdir() or getdents() system call, and that is determined by the underlying filesystem. Unless you are running in a very narrowly defined environment, it is unwise to depend on any particular ordering. For many filesystems, the ordering is not meaningful.

pan64 04-21-2013 02:05 AM

Quote:

Originally Posted by rknichols (Post 4935368)
The find program just processes names in whatever order they were obtained by a readdir() or getdents() system call, and that is determined by the underlying filesystem. Unless you are running in a very narrowly defined environment, it is unwise to depend on any particular ordering. For many filesystems, the ordering is not meaningful.

Totally agree, if you need an ordered list just do it yourself

ilesterg 04-21-2013 11:34 PM

Quote:

Originally Posted by rknichols (Post 4935368)
The find program just processes names in whatever order they were obtained by a readdir() or getdents() system call, and that is determined by the underlying filesystem. Unless you are running in a very narrowly defined environment, it is unwise to depend on any particular ordering. For many filesystems, the ordering is not meaningful.

I think I could use the above system calls in my nex steps. Thank you very much.

---------- Post added 04-22-13 at 12:34 PM ----------

Thanks for the input guys. I'll open another thread related to my concern.


All times are GMT -5. The time now is 05:26 AM.