The syntax for find is find <paths> <expression>
, where paths is a list of files and directories to start the search from. find starts from those locations and then recurses (if they're directories).
When you write find . -name MY_FILE.txt
it performs a recursive search under the ./
directory. But if you write find MY_FILE.txt
then you're telling it to start the search at ./MY_FILE.txt
, and so it does:
$ strace -e file find MY_FILE.txt
...
newfstatat(AT_FDCWD, "MY_FILE.txt", 0x556688ecdc68, AT_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)
...
(No such file or directory)
: No such file or directory
+++ exited with 1 +++
Since the path doesn't exist, it only takes a single system call to determine that there's no such file. It calls newfstat()
, gets a No such file or directory
error, and that's that.
In other words, find MY_FILE.txt
isn't equivalent to find . -name MY_FILE.txt
. Heck, I wouldn't even call it useful because you're not asking it to search. You're just asking it to tell you if MY_FILE.txt
exists in the current directory or not. But you could find that out by simply calling ls MY_FILE.txt
.
Here's the difference:
[~]$ cd /usr
[/usr]$ find . -name sha384sum
./bin/sha384sum
[/usr]$ find sha384sum
find: ‘sha384sum’: No such file or directory
The first one performs a recursive search and finds /usr/bin/sha384sum
. The second one doesn't recurse and immediately fails bcause /usr/sha384sum
doesn't exist. It doesn't look any deeper. It's done in a nanosecond.