The find Command
find is like a scavenger hunt through every room in the house. You describe what you are looking for, like its name or type, and it searches all the folders for you.
In this page:
Syntax
find directory -name "pattern" -type f|d
The find Command
find searches a directory tree for files and directories matching criteria like name, type, or modification time. find . -name "*.txt" searches the current directory recursively for files ending in .txt.
It's far more powerful than simple globbing for searching nested directory structures.
Note:
find . -name "*.log" -mtime -1 finds .log files modified in the last day — great for log cleanup scripts.Example: The find Command
#!/bin/bash
mkdir -p search_demo
touch search_demo/a.txt search_demo/b.log search_demo/c.txt
find search_demo -name "*.txt"
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
Common Mistakes
- Forgetting to quote patterns, as in
find . -name *.txt, which the shell expands first. - Putting options in the wrong order, such as
-maxdepthafter tests, which gives a warning. - Using
-execwithout ending it with\;or+.
🔒
Chapter Quiz — Complete all 13 topics to unlock
0/13 topics done
Complete these topics first: