Answers:
尝试将其用引号引起来-您正在进入Shell的通配符扩展,因此您要通过的准确查找如下所示:
find . -name bobtest.c cattest.c snowtest.c
...导致语法错误。因此,请尝试以下操作:
find . -name '*test.c'
请注意文件表达式周围的单引号-这些引号将阻止shell(bash)扩展通配符。
echo *test.c
……结果将不是回显扩展通配符,而是外壳本身。简单的教训是,如果您使用通配符,请引用文件规范:-)
find . -type f -printf ‘%TY-%Tm-%Td %TT %p\n’
在网上找到,并遇到“路径必须在表达之前”。问题是引号太“聪明”了。我重新键入了命令,导致引号被替换,并且它运行了。
find
-如果使用通配符*.$variable
,则需要双引号。
从查找手册:
NON-BUGS
Operator precedence surprises
The command find . -name afile -o -name bfile -print will never print
afile because this is actually equivalent to find . -name afile -o \(
-name bfile -a -print \). Remember that the precedence of -a is
higher than that of -o and when there is no operator specified
between tests, -a is assumed.
“paths must precede expression” error message
$ find . -name *.c -print
find: paths must precede expression
Usage: find [-H] [-L] [-P] [-Olevel] [-D ... [path...] [expression]
This happens because *.c has been expanded by the shell resulting in
find actually receiving a command line like this:
find . -name frcode.c locate.c word_io.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
$ find . -name \*.c -print
当我尝试查找无法按@Chris J的答案所述合并为正则表达式的多个文件名时遇到了这个问题,这对我有用
find . -name one.pdf -o -name two.txt -o -name anotherone.jpg
-o
或是-or
逻辑或。有关更多信息,请参见在Gnu.org上查找文件。
我在CygWin上运行它。
find
的msysgit除非你用引号括模式可能会引发此错误:find . -name "*test.c"
。(以防您选择Windowsfind.exe
而不是cmd而