I'm confused with these twe sentences:
find . -name *.cpp
find . -name "*.cpp"
The Regular Expression only works in situation B. I'm glad to learn from U.Who can explain this,more details. Thanks a lot.
In the first command,
Let's say you have two subdirectories with C++ files:
The first command (
Another way to escape the
Your focus here is on the parameter you pass to the "-name" option. We want "find", and not the encompassing Shell (bash / tcsh / zsh) to interpret it.
When you put the "*.cpp", you actually allow the "find" program to see "*.cpp", then perform the transformation to a list of all files ending with ".cpp".
When you just put *.cpp, the Shell performs the replacement before even passing the parameter to the find command (that is called globbing). What the find command actually gets is not a pattern, but a set of files. Which leads to :
"find . -name A.cpp B.cpp ... Z.cpp"
The files with names in italics are NOT parameters of the "-name" flag, thus, the unexpected behavior.
If there are any .cpp files in the current directory where you run the find command, then without the quotes your shell will expand the wildcard and call
With the quotes, the star gets passed through directly to find without expansion.
From find manual