免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3176 | 回复: 2

[文件目录] 关于find命令-name选项的问题,大神请进 [复制链接]

论坛徽章:
0
发表于 2013-10-30 17:03 |显示全部楼层
本帖最后由 想尼尼 于 2013-10-30 17:16 编辑

当前文件夹有a1,a2,a3,b1,b2,b*几个文件。我用find找文件:
(1)find . -name '[ab]*' 正确
(2)find . -name \[ab]* 正确
(3)find . -name [ab]* 出错

man find中说
−name pattern
Base of file name (the path with the leading directories removed) matches shell pattern pattern.
我理解是进行man bash中说的那几种扩展中的Pattern Matching。
第(1)(3)种情况,用单引号括起来,我理解是执行这个命令时,shell会对-name的参数进行扩展,也就是说传给-name的是扩展后的值,

所以要quoted后才保证-name接收的原pattern。

我不明白第(2)种情况,这种backslash的应用方法是怎么回事。
man bash中Pattern Matching这一小节说
Any character that appears in a pattern, other than the special pattern characters described below, matches
itself. The NUL character may not occur in a pattern.
A backslash escapes the following character;
the escaping backslash is discarded when matching. The special pattern characters must be quoted if theyare
to be matched literally.

既然backslash只转义一个character,为什么第(2)中情况会正确呢?

不知道是不是特浅显的问题?勿喷,求解答

论坛徽章:
0
发表于 2013-10-30 17:25 |显示全部楼层
目测和正则有关系,和find命令没啥关系

论坛徽章:
0
发表于 2013-10-30 17:37 |显示全部楼层
find有专门识别RE的选项-regex,-name仅仅做shell的pattern matching扩展
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP