How to tell UNIX to start from the oldest file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to tell UNIX to start from the oldest file?
# 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:
# 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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

To delete the oldest files in a file when file count in the folder exceeds 7

Hi All, I need to delete the oldest file in folder when the file count in the folder exceed 6 ( i have a process that puts the source files into this folder ) E.x : Folder : /data/opt/backup 01/01/2012 a.txt 01/02/2012 b.txt ... (1 Reply)
Discussion started by: akshay01987
1 Replies

2. Shell Programming and Scripting

Deleting the oldest file in a directory

Hey! I have found similar posts both here and on other sites regarding this, but I cannot seem to get my script to work. I want to delete the oldest file in a test directory if there are more than two files. My script is currently: #!/bin/bash MEPATH=/usr/local/bin/test FILECOUNT=`ls... (4 Replies)
Discussion started by: Immolation
4 Replies

3. UNIX and Linux Applications

Finding the oldest file in a directory without ls

I am trying to determine the oldest and most recent files in a huge directory. I am using an ls -tr statement outside my find statement. The directory is too big and I am getting an "arg list too long" error. Is there something I can put in my find statement that doesn't create a list to... (2 Replies)
Discussion started by: hiyofjord
2 Replies

4. Shell Programming and Scripting

Finding the oldest file in a particular directory

Hi all, I am a newbie to scripting and I need your help regarding finding the oldest file in a particular directory. My intention is to remove that oldest file. Are there any options available with the "find" command to do this.. Thanks in advance for your help Pavan (4 Replies)
Discussion started by: pavan_movva
4 Replies

5. Shell Programming and Scripting

Finding the oldest file

Hi:- I need help with a script I need to modify: - what's the best/easiest way to find out the oldest file in a directory and then move this file to another directory? Thanks, (5 Replies)
Discussion started by: janet
5 Replies

6. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies

7. Shell Programming and Scripting

how to grep the oldest file in a directory

Hi, Please help me out I want to grep the oldest file in a directory, could I use "ls" command? and how? thanx in advance (1 Reply)
Discussion started by: ericaworld
1 Replies

8. Shell Programming and Scripting

Removing the oldest file in a directory

Hi all, I need your assistance in removing the oldest file in a directory. I posted the same thread 3 days back and I got the following answer ls -1 -t | tail -1 | xargs rm which is not covering the case when there are directories older than the oldest file. So, could you please... (2 Replies)
Discussion started by: pavan_movva
2 Replies

9. UNIX for Dummies Questions & Answers

UNIX Start-up file location

I would like to know where to find the start-up sequence for UNIX. I would like to find the command that starts the database up and do not know where to look and I'm sure there is a file that contains this info. Where is it??? Thanks in advance. Dave. (3 Replies)
Discussion started by: daveo61
3 Replies

10. UNIX for Dummies Questions & Answers

Oldest File In A Directory

I'm writing a script to find the oldest file in a directory. I know this can be done by using ls -rt | tail -1 but these are rather large directories and that can be somewhat slow since the script will be running constantly. Are there any other ways to do this that would be faster? I looked to... (2 Replies)
Discussion started by: bergerj3
2 Replies
Login or Register to Ask a Question