简体   繁体   English

列出具有正则表达式的文件

[英]list files with regular expression

How can do I list all files using ls that have atleast 2 digits in their name? 如何使用名称中至少有2位数字的ls列出所有文件? I tried this but it gave me error 我尝试了这个但是它给了我错误

ls *.log.[1-9][1-9]*.*
ls: *.log.[1-9][1-9]*.*: No such file or directory

I tried this and it list all files that have 0 as the second digit. 我试过了,它列出了所有以0为第二位的文件。

ls *.log.[1-9][0-9]*.*

Thanks 谢谢

You can actually use find command that supports -regex option: 您实际上可以使用支持-regex选项的find命令:

find . -maxdepth 1 -iregex '.*\.log\.[1-9][0-9].*'

-iregex is used for ignore case comparison. -iregex用于忽略大小写比较。

$ ls | egrep '*.log.[1-9][0-9]*.*'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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