find命令错误提示路径必须在表达式之前
来源:互联网 发布:快手免费刷粉丝软件 编辑:程序博客网 时间:2024/06/06 06:31
1、问题
$touch test1.c test2.c text3.txt$ls//当前目录下有三个文件test1.c test2.c text3.txt $find . -iname *.txt./text3.txt $find . -iname *.c$find: paths must precede expression: test2.cUsage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression] $find . -iname \*.c./test1.c./test2.c$find . -iname "*.c"./test1.c./test2.c
2、原因
(1)
man 1 find
-name pattern Base of file name (the path with the leading directories removed) matches shell pattern pattern. The metacharacters (`*', `?', and `[]') match a `.' at the start of the base name (this is a change in findu‐tils-4.2.2; see section STANDARDS CONFORMANCE below). To ignore a directory and the files under it, use -prune; see an example in the description of -path. Braces are not recognised as being special, despite the fact that some shells including Bash imbue braces with a special meaning in shell patterns. The filename matching is performed with the use of the fnmatch(3) library function. Don't forget to enclose the pat‐tern in quotes in order to protect it from expansion by the shell. -iname pattern Like -name, but the match is case insensitive. For example, the patterns `fo*' and `F??' match the file names `Foo', `FOO', `foo', `fOo', etc. In these patterns, unlike filename will match the file `.foobar'. Please note that you should quote patterns as a matter of course, otherwise the shell will **expand any wildcard characters in them**.NON-BUGS $ find . -name *.c -print find: paths must precede expression Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression] This happens because *.c has been expanded by the shell resulting in find actually receiving a command line like this: find . -name bigram.c code.c frcode.c locate.c -print That command is of course not going to work. Instead of doing things this way, you should enclose the pattern in quotes or escape the wildcard: $ find . -name \*.c -print
(2)
find -name 选项后面只能支持一个文件的搜索。
“*”是shell的metacharacter(元字符)。
如果直接是 *.txt, 则shell会解析为test3.txt(当前目录下只有一个.txt文件), 作为 pattern,传递给find。
变为: find . -iname test3.txt。故正确。
如果直接是 *.c, 则shell会解析为test1.c test2.c(当前目录下有两个.c文件), 作为 pattern,传递给find。
变为: find . -iname test1.c test2.c。对test2.c,其前面没有选项,故报错。
如果直接是 \*.c 或 “*.c”, 则shell 会把 它当作参数 *.c ,传给find处理。
参考文献:
[1] http://blog.csdn.net/firefoxbug/article/details/7618188 作者:firefoxbug
[2] Linux的man手册 作者:so many people
0 0
- find命令错误提示路径必须在表达式之前
- find命令错误提示“路径必须在表达式之前”的解决方法
- 完美解决“find: 路径必须在表达式之前:”
- 错误提示:以前的某个程序安装已在安装计算机上创建挂起的文件操作。运行安装程序之前必须重新启动计算机
- 安装SQL Server 遇到错误提示:以前的某个程序安装已在安装计算机上创建挂起的文件操作。运行安装程序之前必须重新启动计算机!。
- 安装SQL Server 遇到错误提示:以前的某个程序安装已在安装计算机上创建挂起的文件操作。运行安装程序之前必须重新启动计算机!。
- 错误1500。另一个程序正在进行。在继续此安装之前您必须完成另外安装。
- 在ubuntu中ipython命令import requests提示错误
- Linux命令错误提示
- find 命令结合 正则表达式
- find命令处理指定时间之前的文件命令
- 数据在SQLLDR的时候提示错误,在逻辑记录结束之前未找到列(使用 TRAILING NULLCOLS)
- 数据在SQLLDR的时候提示错误,在逻辑记录结束之前未找到列(使用 TRAILING NULLCOLS)
- 在表单必填项之前加上提示
- caffe makefile 提示路径错误
- linq中union错误:必须在其目标列表中有相同数目表达式(转)
- SQL Server安装错误 “以前的某个程序安装已在安装计算机上创建挂起的文件操作。运行安装程序之前必须重新启动计算机”错误
- SQL Server安装 提示 以前的某个程序安装已在安装计算机上创建挂起的文件操作。运行安装程序之前必须重新启动计算机
- VIM命令大全
- Unity3D 第二章 常用操作
- 求职总结
- IOS tabBarController 嵌套navigationController 实现多个界面的跳转
- 日经春秋 20151027
- find命令错误提示路径必须在表达式之前
- C语言制作一个简易的计算器(加、减、乘、除、取模)
- 多继承 虚继承
- Android的http协议
- OC 复合问题 男人和女人问题
- POJ 2484 - A Funny Game
- [Leetcode]Reverse Linked List II
- Unity3D 第八章 实例化
- hdoj 2227 Find the nondecreasing subsequences 【树状数组优化dp】