LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1245|回复: 7

find 的一个奇怪问题

[复制链接]
发表于 2007-2-8 15:21:07 | 显示全部楼层 |阅读模式
要在当前目录下找出所有以conf为后缀名的文件,用

[root@drive4 etc]# find ./ -type f -name *.conf
find: paths must precede expression
Usage: find [path...] [expression]

不行,要用引号引起来才行:

[root@drive4 etc]# find ./ -type f -name "*.conf"
./modules.conf
./host.conf
./nsswitch.conf
./ld.so.conf
....

但是如果是查找其他后缀名的文件,不用引号也可以:

[root@drive4 etc]# find ./ -type f -name *.sh
./profile.d/glib2.sh
./profile.d/colorls.sh
./profile.d/less.sh
./profile.d/which-2.sh

试了很多后缀名, *.conf , *conf, *config 一定要用引号才行(或者还有其他更多),其他字母组合就可以不用引号,为什么?难道find命令专门对config文件做了限制?
发表于 2007-2-10 14:00:16 | 显示全部楼层
  1. yongjian@elivize:[ 22:54:16 ] /home/yongjian ] $ find /etc/ -name *.conf
  2. /etc/3ddesktop/3ddesktop.conf
  3. /etc/X11/xorg.conf
  4. /etc/adduser.conf
  5. /etc/apache/httpd.conf
  6. /etc/apache/srm.conf
  7. /etc/apache/conf.d/nagios2.conf
  8. /etc/apache/access.conf
  9. /etc/apache/modules.conf
  10. /etc/apt/apt-file.conf
  11. /etc/apt/apt.conf
  12. /etc/apt/listchanges.conf
  13. /etc/apt/apt-build.conf
  14. /etc/ca-certificates.conf
  15. ...
复制代码
Don't see any problems... looks like its your environment issue.
回复 支持 反对

使用道具 举报

发表于 2007-2-13 20:07:07 | 显示全部楼层
因为 * 会被shell expand成一个list ,*.conf => modules.conf host.conf ...  
当前目录下有 *.conf 文件,所以错了

而你当前目录下没有  *.sh 文件,所以没出错
回复 支持 反对

使用道具 举报

发表于 2007-2-14 01:54:32 | 显示全部楼层
Post by ccpp0
因为 * 会被shell expand成一个list ,*.conf => modules.conf host.conf ...  
当前目录下有 *.conf 文件,所以错了

而你当前目录下没有  *.sh 文件,所以没出错

老大第一贴就出手不凡呀!
回复 支持 反对

使用道具 举报

发表于 2007-2-26 18:09:00 | 显示全部楼层
我也常遇到这种问题,现在明白了。
回复 支持 反对

使用道具 举报

发表于 2007-2-26 18:57:27 | 显示全部楼层
好像不加“”只能在最多有一个匹配文件的时候工作,超过一个时就会出错的说。
  1. [hu@localhost dd]$ ls
  2. 2.conf  d.conf  dd1.cf  dd2.cf
  3. [hu@localhost dd]$ find /home/hu/temp/dd -name *.conf
  4. find: paths must precede expression
  5. Usage: find [path...] [expression]
  6. [hu@localhost dd]$ rm 2.conf
  7. [hu@localhost dd]$ find /home/hu/temp/dd -name *.conf
  8. /home/hu/temp/dd/d.conf
  9. [hu@localhost dd]$ find --version
  10. GNU find version 4.1.20
复制代码
回复 支持 反对

使用道具 举报

发表于 2007-2-26 21:15:07 | 显示全部楼层
find /home/hu/temp/dd -name *.conf
->
find /home/hu/temp/dd -name \*.conf
或者
find /home/hu/temp/dd -name "*.conf"
回复 支持 反对

使用道具 举报

发表于 2007-2-26 22:13:12 | 显示全部楼层
又见“晨想” ! 欢迎正名归来!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表