In bash, I would like to use the command find
to find files which contain the numbers from 40 to 70 in a certain position like c43_data.txt. How is it possible to implement this filter in find
?
I tried file . -name "c**_data.txt" | gr开发者_运维技巧ep 4
, but this is not very nice.
Thanks
Perhaps something like:
find . -regextype posix-egrep -regex "./c(([4-6][0-9])|70)_data.txt"
This matches 40 - 69, and 70.
You may also use the iregex
option for case-insensitive matching.
$ ls
c40_data.txt c42_data.txt c44_data.txt c70_data.txt c72_data.txt c74_data.txt
c41_data.txt c43_data.txt c45_data.txt c71_data.txt c73_data.txt c75_data.txt
$ find . -type f \( -name "c[4-6][0-9]_*txt" -o -name "c70_*txt" -o -name "c[1-2][3-4]_*.txt" \) -print
./c43_data.txt
./c41_data.txt
./c45_data.txt
./c70_data.txt
./c40_data.txt
./c44_data.txt
./c42_data.txt
Try something like:
find . -regextype posix-egrep -regex '.\*c([3-6][0-9]|70).\*'
with the appropriate refinements to limit this to the files you want
ls -R | grep -e 'c[4-7][0-9]_data.txt'
find
can be used in place of ls
, obviously.
精彩评论