proxy代理   soft软件   IT 业界特快   norton 诺顿病毒库   代理列表   search FTP搜索   whois IP地理位置   blog 追求完美  
money理财   life生活   RSS聚合门户   firefox WEB浏览器   免费域名   typeset 假古文   AntiVirus 反病毒   ipcn 站点导航  

« 水木社区开设 TOP100/积分统计百强 版面 | Main | IPCN.org IPCHINA.org 域名坏掉的最新进展 »

February 7, 2006

find 查找匹配时的用法: 必须加引号

版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明。
https://windtear.net/archives/2006/02/07/000910.html
http://windtear.net/archives/2006/02/07/000910.html

find 查找匹配时的用法: 必须加引号

上午看水木社区 LinuxApp讨论 find 用法 就回了一下
写这篇blog主要是想说 find 查找匹配时 必须要加引号(' " 均可)

匹配就是出现了 * ? [] \ 至少其中之一
如果不加引号(' ")  shell 会先展开进而导致查找失败

http://www.newsmth.org/bbscon.php?bid=392&id=321594

发信人: windtear (追求完美), 信区: LinuxApp
标  题: Re: 弱问find / -name *.rpm 和 find / -name '*.rpm'的区别
发信站: 水木社区 (Tue Feb  7 11:52:14 2006), 站内

正确解释:
出现 * ? [] \ 必须加 ' 或者 "
否则shell会先自动展开

【 在 yangfang (Happy Everyday) 的大作中提到: 】
: 这两条命名我试了一下,有些情况两个都能用
: 有些情况只有后者能用
: 具体情况记不清了,都是正常使用中的Redhat Linux ES4
: ...................

--

※ 来源:·水木社区 newsmth.net·[FROM: 219.142.172.*]


find 属于 findutils
官方主页:
http://www.gnu.org/software/findutils/

相关文档:
http://www.gnu.org/software/findutils/manual/find.html
http://www.gnu.org/software/findutils/manual/html_mono/find.html

2.1.4 Shell Pattern Matching

find and locate can compare file names, or parts of file names, to shell patterns. A shell pattern is a string that may contain the following special characters, which are known as wildcards or metacharacters.

You must quote patterns that contain metacharacters to prevent the shell from expanding them itself. Double and single quotes both work; so does escaping with a backslash.

*
    Matches any zero or more characters.
?
    Matches any one character.
[string]
    Matches exactly one character that is a member of the string string. This is called a character class. As a shorthand, string may contain ranges, which consist of two characters with a dash between them. For example, the class [a-z0-9_] matches a lowercase letter, a number, or an underscore. You can negate a class by placing a ! or ^ immediately after the opening bracket. Thus, [^A-Z@] matches any character except an uppercase letter or an at sign.
\
    Removes the special meaning of the character that follows it. This works even in character classes.
本blog WWW

Posted by windtear at February 7, 2006 2:26 PM

本站使用中的任何问题,请与 windtear @ windtear.net 联系
Copyright© 1999-2024 Windtear. All rights reserved.