Find command - result order


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find command - result order
# 1  
Old 01-20-2011
Find command - result order

Hi!

Could you please explain why the result order isn't in reverse time order as it is requestet by "xargs ls -ltr" command (ksh shell)? There are about 5000 files in dir.

Code:
$ find . -name "*201010*" -print |xargs ls -ltr |tail
-rw-r--r--   1 oracle     oinstall     54326 Nov 25 20:32 ./NP20101035623_W.log
-rw-r--r--   1 oracle     oinstall   1216870 Nov 29 09:50 ./201010308_W_OK.IS
-rw-r--r--   1 oracle     oinstall         2 Nov 29 10:03 ./201010392708_W.dsc
-rw-r--r--   1 oracle     oinstall     54428 Nov 29 10:03 ./201010312708_W.log
-rw-r--r--   1 oracle     oinstall       171 Dec  7 13:20 ./20101031_130937_W_OK.IS
-rw-r--r--   1 oracle     oinstall     54312 Dec  7 13:33 ./20101031_W.log
-rw-r--r--   1 oracle     oinstall       257 Jan 12 12:20 ./20101031W_OK.IS
-rw-r--r--   1 oracle     oinstall     54309 Jan 12 12:34 ./20101031W.log
-rw-r--r--   1 oracle     oinstall    215752 Oct  7 11:50 ./07102010__W_OK.IS.gz
-rw-r--r--   1 oracle     oinstall        71 Oct  7 18:05 ./20100930_W.dsc.gz




Thank you very much!

Last edited by radoulov; 01-20-2011 at 12:54 PM.. Reason: Code tags, please!
# 2  
Old 01-20-2011
Because xargs processes n (not all) files at a time.
To get the desired result you need to sort the list after the entire resultset is available.
I suppose that something like this might work (untested):

Code:
perl -e'
  print join $/, sort { 
    -M $b <=> -M $a 
    } split $/, qx/find . -name "*201010*"/
    '


Last edited by radoulov; 01-20-2011 at 01:04 PM.. Reason: Corrected.
# 3  
Old 01-20-2011
I can't explain how the last two files appear in your sample because the file names do not contain the string "201010" (unless there are bad characters in the file name?).

Anyway, here is one way of preserving the order.

Code:
ls -1tr|grep "201010"|while read filename
do
  if [ -f "${filename}" ]
  then 
      ls -lad "${filename}"
  fi
done


Afterthought:
If (horror of horrors) you have a file called "*" or perhaps containing "*" I can explain the anomoly.

Last edited by methyl; 01-20-2011 at 05:38 PM.. Reason: typos & afterthought
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to print the "grep" result as specified keyword order?

I have a content.xls file as given below, NC_020815.1 1891831 1894692 virb4_A0A0H2X8Z4_ 1 954 1945 NC_020815.1 1883937 1886123 vird4_A0A0P9KA26_ 1 729 1379 NC_020815.1 2976151 2974985 virb10_H8FLU5_Ba 1 393 478 NC_020815.1 2968797 2967745 virb6_A0A0Q5GCZ4 5 398 499... (2 Replies)
Discussion started by: dineshkumarsrk
2 Replies

2. Shell Programming and Scripting

Linux find command seems to not transmit all the result to the '-exec command'

Hello. From a script, a command for a test is use : find /home/user_install -maxdepth 1 -type f -newer /tmp/000_skel_file_deb ! -newer /tmp/000_skel_file_end -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc' Tha command... (3 Replies)
Discussion started by: jcdole
3 Replies

3. Shell Programming and Scripting

Unexplained result of 'find' command

Given this bit of script: retprd=$1 find ${extrnllogdir} -name "*.log" -mtime +$retprd -exec ls -l {} \; >> $logfile produces this (with 'set -x') ++ find /xfers/oracle/dw/data -name '*.log' -mtime +60 -exec ls -l '{}' ';' find: /xfers/oracle/dw/data/cron: Permission denied Where is he... (5 Replies)
Discussion started by: edstevens
5 Replies

4. UNIX for Dummies Questions & Answers

Listing only the files under a directory from the result of find command

Hi, I have a main folder 'home'. Lets say there is a folder 'bin' under 'home'. I want to check the list of files under subdirectories present under the /bin directory created in the last 24 hours. I am using the following find command under home/bin directory: find . -mtime -1 -print ... (3 Replies)
Discussion started by: DJose
3 Replies

5. UNIX for Dummies Questions & Answers

Strange result using find command.

I created a file with the permissions of 776. When I ran the command find /root/Desktop -perm -644 -type f The created file shows up as part of the results. Doesn't -perm -mode mean that for global, only 4(read) and 2(write) can be accepted ? (2 Replies)
Discussion started by: Hijanoqu
2 Replies

6. UNIX for Dummies Questions & Answers

Any way to get find command o/p in chronological order?

Hi friends, I am using below script to gzip files after naming them in a particular order. but I intend to name them in numerical order as per their timings(earlier updated fle with a smaller numeric extension than later updated),but this script is not working as planned. please help with... (7 Replies)
Discussion started by: Jcpratap
7 Replies

7. UNIX for Dummies Questions & Answers

Help - Find command with list of files modified descending Order

Hi, I would like to know the command to get the files order in descending order with "FIND" command. Appreciate your help Thanks (4 Replies)
Discussion started by: TonySolarisAdmi
4 Replies

8. Shell Programming and Scripting

sh : Problem with the result of a find command

Hi I'm working on solaris and I'm trying to run a script. The part listed here does not work properly, the result of the find command is not in the output file /tmp/result (I've checked the find command , executing the shell with sh -x , it seems correct). It seems like I've lost the standard... (4 Replies)
Discussion started by: frenchwill
4 Replies

9. Windows & DOS: Issues & Discussions

Setting a variable to result of FIND command

I am working on a batch script where a filter is placed on a directory, and the files that come out of that filter have to be copied into another directory. More specifically, I am trying to set the results of a FIND command to a variable, so that I may access this variable / file later. The... (2 Replies)
Discussion started by: JP Favara
2 Replies

10. UNIX for Advanced & Expert Users

find command not returning any result

I am looking for all the header files (*.h).. which as per documentation of the UNIX system shouldbe there. I am using find / -name *.h -print But it does't give anything. My question is under what condition the "find" condition will fail to find the file? What is the work around. ... (4 Replies)
Discussion started by: rraajjiibb
4 Replies
Login or Register to Ask a Question