Korn shell get latest file matching pattern

时间:2016-02-12 19:49:14

标签: linux unix ksh

Need help to write a korn shell script for the below.

Have to write the script in dir ..../script

Have the below files in dir ..../files

Have 2 file patterns 
xxx892_1.txt
xxx367_8.txt
xxx356_9.txt
yyy736_9.txt
yyy635_7.txt

Need to get the latest files(last created) matching pattern

xxx and yyy i.e from above xxx356_9.txt, yyy635_7 and ftp them over.

Please need help with this. Thanks.

1 个答案:

答案 0 :(得分:0)

如果最新你的意思是时间戳。你可以做这样的事情

ls -t xxx* | head -1  #this will give you the latest modified file
ls -t yyy* | head -1 

以上将为您提供可用于FTP的文件名称。