Issue
I have the following script:
#!/bin/sh
HOST='host'
USER='[email protected]'
PASSWD='pwd'
for FILE in *.avi
do
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
binary
put $FILE
rm FILE
quit
done
END_SCRIPT
exit 0
How do I ensure that I process the oldest file first? I have seen a lot of hacks that use ls -t, but there has to be a simpler way.
Solution
I would modify your for
loop with this:
for FILE in `ls -tU *.avi`
do
#
# loop content here with ${FILE}
#
done
From the ls
docs:
-t Sort by time modified (most recently modified first) before
sorting the operands by lexicographical order.
-U Use time of file creation, instead of last modification for
sorting (-t) or long output (-l).
Answered By - mjuarez Answer Checked By - Mary Flores (WPSolving Volunteer)