Sorted Find
|
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/kshtouch /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
|
Use following form to reply to current message: