I want to know what is the difference between this two commands..
find . –name *.txt
find . –name "*.txt"
I run it in the system and cant find any difference,
what does the sign " "
do?
I want to know what is the difference between this two commands..
find . –name *.txt
find . –name "*.txt"
I run it in the system and cant find any difference,
what does the sign " "
do?
When you don't use quotes around the glob pattern, i.e. when you say:
find . -name *.txt
then the shell would expand *.txt
to the matching files in the current directory before passing those as an argument to find
. If no file matching the pattern is found, then the behaviour is similar to the quoted variant.
When you use quotes, i.e. when you say:
find . -name "*.txt"
the shell passes *.txt
as an argument to find
.
Always use quotes when specifying a glob (esp. when used as an argument to find
).
An example might help:
$ 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