简体   繁体   中英

ksh can not grab latest files successfully

Trying to pull latest 3 files from dir. Seems only certain ones come back.

INPUT_FILE_NAME=*.txt

DATADIR=/mypath

LATEST_DATADIR_FILE=`ls -l $DATADIR/$INPUT_FILE_NAME | tail -3 | cut -c94-105`

Within this directory lets say there are file names FFile.txt & AFile.txt. The above will only bring the latest files back for FFile.txt even though one of the last files received has a AFile.txt name. How can I get it to bring back the latest files if they start with F or A. I tried incorporating "[A|F]*.txt" to the input file name with no luck.

How can I get it to bring back the latest files if they start with F or A.

You can use:

ls -lrt "$DATADIR"/[FA]*.txt | tail -3

您需要/^(A|F)\\w+\\.txt/^ ,这意味着字符串的开始

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM