0
find . -name 'my*'

The quotes avoid the shell expansion - without them the shell would replace my* with the list of files whose names begin with my in the current directory.

What thus the above statement mean? Isn't it doing the same thing I mean looking for file names beginning with my?

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Fest3er
0
find . -name 'my*'

The quotes avoid the shell expansion - without them the shell would replace my* with the list of files whose names begin with my in the current directory.

What thus the above statement mean? Isn't it doing the same thing I mean looking for file names beginning with my?

Do an exercise:

touch my0
mkdir foo
touch foo/my1
find -name 'my*'
find -name my*

and compare results.

0
find . -name 'my*'

The quotes avoid the shell expansion - without them the shell would replace my* with the list of files whose names begin with my in the current directory.

What thus the above statement mean? Isn't it doing the same thing I mean looking for file names beginning with my?

No. While it can be the same, it is not always or necessarily the same. Quoting or escaping the asterisk lets find use the asterisk as a wildcard character.

It is the same when your current directory contains no files matching that glob pattern. In this case, the shell passes your my* to find as-is.

It is not the same if your current directory contains one or more files starting with my. For example, if you have just one file named myfile, find will recursively search your directory tree for files named myfile. If you have two or more files that begin with my, you will get a syntax error.

This is why quoting (using args like "my*") or escaping (using args like my\*) arguments that contain shell meta-characters is important.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.