我有以下脚本:
#!/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
Run Code Online (Sandbox Code Playgroud)
如何确保首先处理最旧的文件?我见过很多使用 ls -t 的 hack,但必须有更简单的方法。
我会for
用这个修改你的循环:
for FILE in `ls -tU *.avi`
do
#
# loop content here with ${FILE}
#
done
Run Code Online (Sandbox Code Playgroud)
从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).
Run Code Online (Sandbox Code Playgroud)