Nicely spotted. This one of the reasons why in the content I simplified specifically as follows.
A simplified usage of this command looks like
find [location] -name ['filename'] .
Note the single quotes in filename. They’re always supposed to be there, they’re part of the (simplified) usage of the command. They’re not acting with the same function as when using glob patterns to match filenames.
Glob patterns are used to match filenames as arguments of commands. What we’re passing to
find is a pattern, not actual file names.
I’ll try to clarify this below. We’ll make use of the command
echo !$; the argument
!$ is the last argument(s) of the previous command.
Here’s an example.
$ cal -m 3
do se te qu qu se sá
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
$ echo !$
cal -m 3, which shows the calendar for the third month of the current year. The argument
3 is the last argument in the command, and as such the second line of
echo !$ is
Let’s setup a mini environment first. We’ll create a directory and files called
?q in that directory.
$ mkdir mcriotto
$ cd mcriotto
$ touch dq '?q'
We’ll now run
ls ?q, which we expect to list the same files as above, and then check the previous argument.
$ ls ?q
$ echo !$
As you can see, the last argument isn’t
?q, but rather the filenames which the pattern
Now let’s search for these very same files using the same pattern.
[email protected]:/media/HDD Disk/Scratch/mcriotto$ find . -name '?q'
And let’s check the last argument.
$ echo !$
So you see that the last argument of the
find command we ran is the pattern itself, where as for
ls it was the actual filenames.
To address this, that’s because
find takes patterns as inputs, not filenames. To draw a parallel with
ls takes filenames as input, so the shell expands the pattern to match the file names,
ls never sees the pattern, where as
find sees exactly the pattern.
I hope this helps.