← Back to Bash Course | Chapter 9: File Testing & Filesystem | Lesson 7 of 13

The find Command

In this page:

  1. The find Command

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

bash
#!/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 run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.