简体   繁体   中英

Unix - File Search with Regular expression

find . -iname "abc_v?_test.txt" -print

Which finds all the files

abc_v1_test.txt, abc_v2_test.txt, ..., abc_v9_test.txt

But how can I get additionally get abc_v10_test.txt, abc_v11_test.txt..

您也可以使用-regex选项:

find . -regextype posix-egrep -iregex ".*abc_v[0-9]{1,2}_test\.txt$"

You still have the option to get all files and pass them to grep , ack or ag :

find . | ag 'abc_v\d+_test\.txt'

note you can replace ag by egrep

Finally, I have implemented in this way

find . -iname "abc_v*_test.txt" -print.

is there any Regular expression that accepts only 1 or 2 numbers after V?

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