我想知道这两个命令有什么区别..
find . –name *.txt
find . –name "*.txt"
我在系统里运行,没发现有什么不同,
符号 ""
有什么作用?
最佳答案
当您不在 glob 模式周围使用引号时,即当您说:
find . -name *.txt
然后 shell 会将 *.txt
扩展为 当前目录 中的匹配文件,然后将它们作为参数传递给 find
。如果未找到与模式匹配的文件,则行为类似于引用的变体。
当您使用引号时,即当您说:
find . -name "*.txt"
shell 将 *.txt
作为参数传递给 find
。
在指定 glob 时始终使用引号(尤其是当用作 find
的参数时)。
一个例子可能会有所帮助:
$ touch {1..5}.txt # Create a few .txt files
$ ls
1.txt 2.txt 3.txt 4.txt 5.txt
$ find . -name *.txt # find *.txt files
find: paths must precede expression: 2.txt
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
$ find . -name "*.txt" # find "*.txt" files
./2.txt
./4.txt
./3.txt
./5.txt
./1.txt
关于linux - 发现之间的区别。 –name *.txt 并找到 . –名称 "*.txt",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19604349/