在bash脚本中,如何循环浏览按日期排序的文件 [英] In a bash script how to loop through files sorted by date
本文介绍了在bash脚本中,如何循环浏览按日期排序的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下脚本:
#!/bin/sh
HOST='host'
USER='user@example.com'
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
如何确保首先处理最早的文件?我已经看到很多使用ls -t的技巧,但是必须有一种更简单的方法.
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.
推荐答案
我将使用以下方法修改您的 for
循环:
I would modify your for
loop with this:
for FILE in `ls -tU *.avi`
do
#
# loop content here with ${FILE}
#
done
从 ls
文档中
-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).
这篇关于在bash脚本中,如何循环浏览按日期排序的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文