find: Searching for Files
By name.
You know a file exists somewhere, but you can't remember where you saved it. Instead of opening folder after folder, let the find command search the tree for you.

- Where did I save it?
- Don't search by hand
- find searches the tree
Find by name
Find takes a starting folder, and then what to look for. Find dot, dash name, style dot CSS, searches the current folder, and every folder inside it. It prints the path to the file it found, deep inside projects.
find . -name style.css ./projects/website/css/style.css
Find with a pattern
You can use wildcards too. Put the pattern in quotes, so find gets the star, not the shell. Every file whose name ends in dot TXT, anywhere in your home. Dash I name ignores capital letters, so dash I name, cv star, finds cv dot TXT, however it's written.
find . -name "*.txt" ./Documents/cv.txt ./Documents/report.txt ./Music/playlist.txt ./todo.txt ./notes.txt find . -iname "CV*" ./Documents/cv.txt
Searching the whole system
To search the whole computer, start from slash. But many folders belong to other users, or to the system. Find will print permission denied for those. Adding two greater than slash dev slash null hides those error messages. We'll learn exactly how that works in a later lesson.
| key | value |
|---|---|
| find / -name x | search everything |
| Permission denied | folders you can't read |
| 2>/dev/null | hide the errors |
| Start small | search ~ first |
Summary
Find, a starting folder, and dash name, searches a whole tree. Quote your wildcards. Next, finding files by type, size, and age.
Key takeaways- find . -name file
- find . -name "*.txt"
- -iname ignores case