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 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. |
Don't expect anything, files can come in any order. (see also ls -U)
|
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" |
Thanks for the confirmation. Cheers!
|
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 Code:
michael@x054:[/home/michael]ls -aUi | head Code:
michael@x054:[/home/michael]find . -ls | head |
True, in AIX 'ls -U' doesn't mean unsorted. Also, in AIX 6+ (unlike AIX 5) find does sort by filename.
|
Quote:
|
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.
|
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. |
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.
|
Quote:
|
Quote:
---------- 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. |