grep -r looks inside files. find looks for the files themselves, by their names. It starts at a directory and looks at all levels under it.
With no test, find writes every path under the start directory, also the start directory:
learner@tidepool:~$ find conf
conf
conf/a.conf
conf/sub
conf/sub/b.conf-name: match the name
-name takes a pattern, with the same wildcards that you know: *, ?, [ ].
learner@tidepool:~$ find ~/config -name "*.conf"
/home/learner/config/till.conf
/home/learner/config/web/site.confPut quotes around the pattern. Without them, the shell changes *.conf into the names in the current directory before find starts. The quotes give the * to find, and find uses it at all levels.
-iname is the same as -name, but uppercase and lowercase are the same.
-type: files or directories
| Test | Keeps |
|---|---|
-type f | Files |
-type d | Directories |
Put tests together
Each item must pass every test on the line:
learner@tidepool:~$ find ~/shop -type f -name "week-*"This writes the files, not directories, with names that start with week-.
| Question | Command |
|---|---|
| Which files have this text in them? | grep -rl TEXT DIR |
| Which files have this name? | find DIR -name "PATTERN" |