How to tell UNIX to start from the oldest file?

Tags
shell scripts, sorted, while start oldest file

 
Thread Tools Search this Thread
# 1  
Old 08-31-2018
How to tell UNIX to start from the oldest file?

Hello,
I have a simple while loopinside the script and I wish to tell unix to start reading from the oldest txt file. So, in case some new txt files are transferred into the same folder, the script will not take into consideration until all older files are completely processed. How may I do this?

Let's say, below process takes six hours to be completed and I do not wish to wait until then:
Code:
cd /home/tmp
while i in *.txt
 do
     ffmpeg $what_soever_command$
sleep 5
mv $i /home/tmp/junkie/$i
 done

Should I list all txt files according to their age
Code:
ls -lt

And then sort from older to newer. Is there a nice way?

Kind regards
Boris
# 2  
Old 08-31-2018
Why not:
Code:
cd /home/tmp
ls -rt *.txt | while IFS= read -r i
do
	ffmpeg $what_soever_command$
	sleep 5
	mv "$i" "/home/tmp/junkie/$i"
done

?
These 2 Users Gave Thanks to Don Cragun For This Post:
baris35 (08-31-2018) jim mcnamara (09-01-2018)
# 3  
Old 08-31-2018
Hello Don,
Thanks... Have just checked your code now and voila!
Lesson learnt!

Code:
  -r, --reverse              reverse order while sorting
  -t                         sort by modification time, newest first


Kind regards
Boris
# 4  
Old 09-01-2018
Code:
if [ -r job.pid ]
then
     exit 1
fi
echo $$ >job.pid

cd /home/tmp

  ls -rt *.txt | while IFS= read -r i 

do     ffmpeg $what_soever_command$     

sleep 5     

mv "$i" "/home/tmp/junkie/$i"
 done
 rm job.pid

Two other considerations:
If the text file is large, then a file may appear in the list while it is being received, and processed while it is still incomplete.
Remove any job.pid files that exist on system boot up.

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Shell script to pick the oldest file hemanthsaikumar Shell Programming and Scripting 5 02-14-2013 05:29 AM
To delete the oldest files in a file when file count in the folder exceeds 7 akshay01987 UNIX for Dummies Questions & Answers 1 10-01-2012 03:32 AM
Moving files only by oldest file one at a time chamajid Shell Programming and Scripting 2 05-21-2012 05:30 PM
Access the oldest file in a dir rajesh8s UNIX for Dummies Questions & Answers 6 10-17-2010 10:57 AM
UNIX script to check file and start the informatica server gurukrishnan Shell Programming and Scripting 0 05-29-2010 06:39 AM
Deleting the oldest file in a directory Immolation Shell Programming and Scripting 4 12-14-2009 04:31 AM
Finding the oldest file in a directory without ls hiyofjord UNIX and Linux Applications 2 10-16-2009 01:27 AM
Finding the oldest file in a particular directory pavan_movva Shell Programming and Scripting 4 04-08-2009 08:24 AM
Finding the oldest file janet Shell Programming and Scripting 5 03-23-2009 11:31 AM
Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names nikosey Shell Programming and Scripting 6 07-30-2008 10:46 PM
how to grep the oldest file under ls command ericaworld Shell Programming and Scripting 7 05-30-2007 02:12 PM
how to grep the oldest file in a directory ericaworld Shell Programming and Scripting 1 05-29-2007 02:24 PM
Removing the oldest file in a directory pavan_movva Shell Programming and Scripting 2 10-10-2006 12:38 PM
UNIX Start-up file location daveo61 UNIX for Dummies Questions & Answers 3 07-22-2002 09:35 AM
Oldest File In A Directory bergerj3 UNIX for Dummies Questions & Answers 2 02-27-2002 03:31 PM