Find files by name in Bash
Search a tree with find . -name, then list only folders with -type d.
Start Interactive Lessonls only sees the current folder. find walks a whole tree. Start in . (here), then add -name or -type so the result is usable.
Windows has a different find that searches inside file text. In Bash, find searches the filesystem by path.
Match a filename: find . -name
-name compares the last part of the path. Quotes stop the shell from expanding *.
Search this folder tree by name!
Locate a hidden file:
find . -name '*.txt' lists every .txt under the current folder, including nested ones.
List folders only: find . -type d
-type d keeps directories. -type f keeps regular files. Combine with -name when you need both filters.
find . -type d
You will see ., then every subfolder. That map is useful before a cleanup or a copy.
Knowledge Check
1 / 3What does find . -name 'secret.txt' search?
References
These documentation links provide authoritative details for the commands used in this article.
Up Next
Use wc -l to count lines, then sort to put names in order.