find -name & -type
Find files anywhere
Lesson 12 of 20 · 8 min · Module 4: Find and organize
When you do not know where a file is, find searches a whole folder tree for you.
Start this lesson →Free. No installation: you write and run the code in your browser, and it is checked automatically.
By the end, you’ll be able to…
- Search a folder tree by name
- Filter results by type
- Quote wildcard patterns
The idea
find folder -name "pattern" searches folder and everything below it. Patterns use wildcards: "*.log" means any name ending in .log. Quote the pattern so the shell passes it to find unchanged. -type f keeps files and -type d keeps folders.
find . -name "*.txt"
find projects -type d
01find walks the whole tree
find . means "start here and look in every folder below". Results are printed as paths relative to where the search started.
find . -name "*.log"./logs/access.log
./logs/app.log
./logs/old/2026-09.log02Why the quotes matter
Without quotes, the shell may expand *.log itself using files in the current folder before find ever sees the pattern. Quotes hand the pattern to find untouched.
03Combine tests
find projects -type f -name "*.html" keeps only files whose names end in .html. Every test you add narrows the result.
Your turn
.log anywhere under your home folder. Then list every folder inside projects, including projects itself.What the checks look for
- Finds all three .log files, including the archived one
- Lists the folders inside projects
Take this with you
find answers "where is it?" across a whole tree of folders.
Go a little further
Use -iname instead of -name to match names regardless of upper or lower case.