Performing a search from the current directory where this file resides, this find command finds the file.
# find . page.tpl.php
However, when I search from a child directory, this command,
# find ../. page.tpl.php
prints out the list of files, WITH the requested file listed in the output,
.././parent_dir/page.tpl.php
However, the results are,
find: `page.tpl.php': No such file or directory
Then when I add the -name argument it works,
# find ../. -name page.tpl.php
I simply forget to use arguments sometimes and the false negative is really aggravating. What's going on?
2 Answers 2
find [path] [expressions]
A filename isn't an expression.
The default action is to print.
For path, ".." is better than "../." you almost never need to include "." unless it's at the start of a relative path.
-
Ok. I appreciate the methodical way you answered my post. That a file name isn't an expression is a lost distinction, which is to say I know you are making a distinction, but I don't understand what it means. And the default print action is perfectly fine. Actually I would want to force the print action when using -name, but it remains silent. I tried .. and learned something which is in a comment follow-up...xtian– xtian2011年06月20日 17:10:06 +00:00Commented Jun 20, 2011 at 17:10
The command find uses:
find [-H] [-L] [-P] [path...] [expression]
Your first example was:
find ../. page.tpl.php
What you did was give find two search paths. As the default expression is print, the contents of the two paths were printed to stdout.
Consider this:
mkdir a b c
touch a/file1 a/file2 b/SANTACLAUS c/MONKEYS
find a b
$ find a b
a
a/file2
a/file1
b
b/SANTACLAUS
Your second example was:
.././parent_dir/page.tpl.php
Here you provided one search path. The error tells you that page.tpl.php wasn't found in CWD. I assume this was due to your not having the file 'page.tpl.php' under the directory 'parent_dir'.
-
No. The file was there. I first performed the find in the same directory. Then descended into a child directory and performed the same find with the relative path ../. I never moved the file, it was still there.xtian– xtian2011年06月20日 17:12:01 +00:00Commented Jun 20, 2011 at 17:12
findhave such funny commandline syntax?" or "What exactly is find doing here?"