LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > AIX
User Name
Password
AIX This forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.

Notices

Reply
 
Search this Thread
Old 04-04-2013, 04:22 AM   #1
ilesterg
Member
 
Registered: Jul 2012
Distribution: CentOS, Debian, Oracle Linux, AIX
Posts: 337

Rep: Reputation: 46
Unhappy 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.
 
Old 04-04-2013, 05:01 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,827

Rep: Reputation: 507Reputation: 507Reputation: 507Reputation: 507Reputation: 507Reputation: 507
Don't expect anything, files can come in any order. (see also ls -U)
 
1 members found this post helpful.
Old 04-04-2013, 06:16 AM   #3
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,953

Rep: Reputation: 1309Reputation: 1309Reputation: 1309Reputation: 1309Reputation: 1309Reputation: 1309Reputation: 1309Reputation: 1309Reputation: 1309Reputation: 1309
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"

Last edited by pan64; 04-04-2013 at 06:17 AM. Reason: typo
 
Old 04-04-2013, 10:46 PM   #4
ilesterg
Member
 
Registered: Jul 2012
Distribution: CentOS, Debian, Oracle Linux, AIX
Posts: 337

Original Poster
Rep: Reputation: 46
Thanks for the confirmation. Cheers!
 
Old 04-18-2013, 07:22 AM   #5
Michael AM
Member
 
Registered: May 2006
Distribution: AIX 5.3, AIX 6.1, AIX 7.1
Posts: 95

Rep: Reputation: 23
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

Last edited by Michael AM; 04-18-2013 at 07:27 AM.
 
Old 04-18-2013, 01:03 PM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,827

Rep: Reputation: 507Reputation: 507Reputation: 507Reputation: 507Reputation: 507Reputation: 507
True, in AIX 'ls -U' doesn't mean unsorted. Also, in AIX 6+ (unlike AIX 5) find does sort by filename.
 
Old 04-19-2013, 06:15 AM   #7
ilesterg
Member
 
Registered: Jul 2012
Distribution: CentOS, Debian, Oracle Linux, AIX
Posts: 337

Original Poster
Rep: Reputation: 46
Quote:
Originally Posted by NevemTeve View Post
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?
 
Old 04-19-2013, 07:19 AM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,827

Rep: Reputation: 507Reputation: 507Reputation: 507Reputation: 507Reputation: 507Reputation: 507
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.
 
Old 04-20-2013, 04:16 AM   #9
Michael AM
Member
 
Registered: May 2006
Distribution: AIX 5.3, AIX 6.1, AIX 7.1
Posts: 95

Rep: Reputation: 23
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.
 
Old 04-20-2013, 11:28 AM   #10
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,511

Rep: Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626
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.
 
1 members found this post helpful.
Old 04-21-2013, 02:05 AM   #11
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,953

Rep: Reputation: 1309Reputation: 1309Reputation: 1309Reputation: 1309Reputation: 1309Reputation: 1309Reputation: 1309Reputation: 1309Reputation: 1309Reputation: 1309
Quote:
Originally Posted by rknichols View Post
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
 
Old 04-21-2013, 11:34 PM   #12
ilesterg
Member
 
Registered: Jul 2012
Distribution: CentOS, Debian, Oracle Linux, AIX
Posts: 337

Original Poster
Rep: Reputation: 46
Quote:
Originally Posted by rknichols View Post
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.
 
  


Reply

Tags
aix, find, ibm


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with find command and rar/unrar command line krakatoa1 *BSD 6 09-11-2012 03:21 PM
[SOLVED] Find a file in directories without using find command sikanders Linux - Newbie 14 08-06-2010 08:47 PM
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 05:55 PM
Single find command to find multiple files? thok Linux - Newbie 7 01-31-2009 04:45 PM
Command interpretation issue in Sed script file angel115 Programming 9 04-21-2006 07:26 PM


All times are GMT -5. The time now is 07:58 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration