use*_*456 3 unix linux shell find
我想知道这两个命令有什么区别..
find . –name *.txt
find . –name "*.txt"
Run Code Online (Sandbox Code Playgroud)
我在系统中运行它并且找不到任何区别,标志有" "什么作用?
当你不在glob模式周围使用引号时,即当你说:
find . -name *.txt
Run Code Online (Sandbox Code Playgroud)
然后shell将扩展*.txt到当前目录中的匹配文件,然后将它们作为参数传递给find.如果找不到与模式匹配的文件,则行为类似于引用的变体.
当你使用引号时,即当你说:
find . -name "*.txt"
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)