简体   繁体   English

带引号的查找命令导致“没有这样的文件”

[英]Find command with quotation marks results in “no such file”

In my directory there are the files: 在我的目录中有以下文件:

file1.txt  fix.log  fixRRRRRR.log  fixXXXX.log  output.txt

In order to understand the find command, I tried a lot of stuff among other things I wanted to use 2 wildcards. 为了理解find命令,我尝试了很多其他事情,我想使用2个通配符。 Target was to find files that start with an f and have an extension starting with an l . 目标是查找以f开头且扩展名为l开头的文件。

$ find . f*.l*

./file1.txt
./fix.log
./fixRRRRRR.log
./output.txt
./fixXXXX.log
fix.log
fixRRRRRR.log
fixXXXX.log

I read in a forum answer to use quotation marks with find find . "f*.l*" 我在论坛答案中读过,在find find . "f*.l*"使用引号find . "f*.l*" find . "f*.l*" with the result: ` find . "f*.l*"

./file1.txt
./fix.log
./fixRRRRRR.log
./output.txt
./fixXXXX.log

It results in find: 'f*.l*': No such file or directory 结果为find: 'f*.l*': No such file or directory

What am I doing wrong, where is my error in reasoning? 我在做什么错,我的推理错误在哪里?

Thanks for an answer. 感谢您的回答。

find doesn't work like that. 找不到那样的东西。 In general find's call form looks like: 通常,find的调用表单如下所示:

find [entry1] [entry2] ... [expressions ...]

Where an entry is a starting point where find starts the search for files. 条目是起点,而find是查找文件的起点。

In your case, you haven't actually supplied any expressions. 就您而言,您实际上没有提供任何表达式。

In the first command (without quotes), the shell expands the wildcards to a list of matching files (in the current directory), then passes the list to find as arguments. 在第一个命令(不带引号)中,shell将通配符扩展为匹配文件的列表(在当前目录中),然后将该列表传递以作为参数find So find . f*.l* 所以find . f*.l* find . f*.l* is essentially equivalent to find . fix.log fixRRRRRR.log fixXXXX.log find . f*.l*本质上等效于find . fix.log fixRRRRRR.log fixXXXX.log find . fix.log fixRRRRRR.log fixXXXX.log . find . fix.log fixRRRRRR.log fixXXXX.log As a result, find treats all of those arguments as directories/files to search (not patterns to search for), and lists all files under . 结果,find将所有这些参数视为要搜索的目录/文件(而不是要搜索的模式),并在下列出所有文件. , (everything) then all files under fix.log (it's not a directory, so that's just the file itself), then all files under fixRRRRRR.log and finally all files under fixXXXX.log . ,(所有内容),然后是fix.log下的所有文件(这不是目录,所以只是文件本身),然后是fixRRRRRR.log下的所有文件,最后是fixXXXX.log下的所有文件。

In the second one (with quotes) it searches for all files beneath the current directory (.) and tries the same for the file literally called "f*.l*". 在第二个文件中(带引号),它搜索当前目录(。)下的所有文件,并对字面名为“ f * .l *”的文件尝试相同的文件。

Actually you are likely seeking for the "-name" expression, which may be used like this: 实际上,您可能正在寻找“ -name”表达式,该表达式可以这样使用:

find . -name "f*.l*"  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM