Computing.Net > Forums > Unix > Sorted Find

Sorted Find

Reply to Message Icon

Original Message
Name: denny
Date: August 20, 2003 at 10:18:01 Pacific
Subject: Sorted Find
OS: HP-UX 11.11
CPU/Ram: HP
Comment:

Hi,

I am trying to return a list of files in a directory older than say 2 minutes and want the files ordered by modification date.

If I try something based on ls -ltr, then I have to pick the date from their and convert to compare to the current date.

If I try something based on find, is their a way to sort the resulting files based on their modification date

In either case, then I will want to process the files one by one


thanks for any info
Denny


Report Offensive Message For Removal


Response Number 1
Name: James Boothe
Date: August 20, 2003 at 12:13:58 Pacific
Reply: (edit)

I would use find to get the list of files older than 2 minutes by aging a comparison file.  There is a startup penalty while the script waits for the comparison file to reach the desired age of two minutes.  But if you want to do this repeatedly every two minutes (like the script below), then it is not an issue.

Of course the find command will return these filenames in whatever sequence.  To get them time-sequenced, I pipe them into an ls command.

#!/bin/ksh

touch /tmp/myscript.run

while true
  do
  touch /tmp/2minutesago
  sleep 119
  for fn in $(find . -type f ! -newer /tmp/2minutesago | xargs ls -tr)
    do
    echo "Do someting with: $fn"
    done
  if [ ! -f /tmp/myscript.run ] ; then
     echo 'Quitting because /tmp/myscript.run is gone'
     break
  fi
  done

exit 0


Report Offensive Follow Up For Removal

Response Number 2
Name: ArnoldF
Date: August 20, 2003 at 14:31:42 Pacific
Reply: (edit)

with linux:
for f in $(ls -tr $(find . -type f -maxdepth 1 -cmin +2))
do
something
done



Report Offensive Follow Up For Removal

Response Number 3
Name: James Boothe
Date: August 21, 2003 at 06:37:35 Pacific
Reply: (edit)

Good tip.

-amin -cmin -mmin -cnewer -iname -iregex -regex

I see a lot of good find options in linux - wish I had some of these in HP-UX.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Sorted Find

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge