CMD Master
Back to Blog
Arnošt Havelka

Find files by name in Bash

Search a tree with find . -name, then list only folders with -type d.

Start Interactive Lesson
Find files by name in Bash

ls 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 *.

Try the command

Search this folder tree by name!

Build the command
find .
Terminal
C:\Users\User>find . -name 'secret.txt'

Locate a hidden file:

Command Prompt
hidden public.txt
C:\Users\User>ls

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.

Command Prompt
folders file.txt
C:\Users\User>ls

Knowledge Check

1 / 3

What does find . -name 'secret.txt' search?

References

These documentation links provide authoritative details for the commands used in this article.

Up Next

Count lines with wc and sort a file

Use wc -l to count lines, then sort to put names in order.