# Finding files: find

Course: Terminal Basics — https://zero2vibecode.com/learn/terminal-basics
Canonical URL: https://zero2vibecode.com/learn/terminal-basics/3-1-finding-files-with-find

`find` walks through a folder and everything under it, listing the files whose names match a pattern.

You know a file exists somewhere in the project. You do not know which folder.

`ls` will not help — it shows one folder at a time. You need something that walks down through everything.

## find

```
find . -name "*.js"
```

```
./src/app.js
./src/utils.js
```

Read the command in three pieces:

- `find` — the command
- `.` — **where** to start, in this case the current folder
- `-name "*.js"` — **what** to match

`find` starts at the place you named and goes down through every folder inside it, at every depth, printing the paths that match.

## The star

`*` in a pattern means "any characters, including none":

| Pattern | Matches |
|---|---|
| `*.txt` | anything ending in `.txt` |
| `app.*` | `app.js`, `app.css`, `app.json` |
| `*test*` | any name with `test` somewhere in it |

Quote the pattern: `-name "*.js"`, not `-name *.js`. Without quotes, the shell tries to expand the star before `find` ever sees it, and you get results that depend on what happens to be sitting in your current folder. Quoting removes the surprise.

## What find does not do

`find` matches **names**. It does not look inside files at all. Searching for a word *inside* your files is a different command — `grep` — and that is the next lesson.

Keeping the two apart saves confusion later:

- `find` — where is the file called something like this?
- `grep` — which files contain this text?

On a real machine `find /` searches the entire disk, which is slow and prints permission errors for system folders you are not allowed to read. Start from a project folder, not from the root.

## Try it

The project has files at two different depths.

1. `ls` — notice you only see the top level: `docs`, `src`, `todo.txt`.
2. `find . -name "*.js"` — both JavaScript files turn up, including the ones nested inside `src`.
3. `find . -name "*.txt"` — three text files, from two different folders.

Compare step 1 with step 3. `ls` showed you one `.txt` file; `find` showed you all three.
