2011-03-28 84 views
0

而不必编写一个shell脚本,我想知道是否有一种方法可以根据一个以上的标准匹配列出文件?命令grep为多个文件?

我知道我可以做:

ls ./files/ | grep samp 

获得包含“SAMP”在文件名中的所有文件的列表......但是,有没有办法说,“列表中的所有文件那场比赛 “SAMP” “examp”?

我已经想通了,

ls ./files/ | grep samp examp 

不工作...

+1

属于http://superuser.com – 2011-03-28 20:19:43

回答

2

使用find - 这是做这种事情更强大,如:

find ./files -name \*samp\* -o -name \*examp\* 
0
ls ./files/ | grep -esamp -eexamp 
0

您可以使用|

ls ./files/ | grep -E 'samp|examp' 

-E是允许使用的扩展(现代)正则表达式。如果您的grep版本不支持这种行为,你需要躲避|

ls ./file/ | grep 'samp\|examp' 
0

可以使用find命令。

find ./files -name \*samp\* -o -name \*examp\* 

-o表示“或”。对于不区分大小写的匹配,您可以使用-iname而不是-name