What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use find DIRECTORY -name 'filename' to search a directory tree. For example, find . -name 'report.txt' searches the current directory and its subdirectories and prints matching paths. Replace . with a directory path to search somewhere else.

Basic command to find a file

The general form is find STARTING_PATH TESTS. The starting path determines where the search begins; the tests determine which entries to report.

find . -name 'report.txt'

This searches recursively from the current directory. To search a specific directory, use its path:

find /home/alex/documents -name 'report.txt'

If you omit the starting path, GNU find uses the current directory. GNU documents this behavior in its find invocation reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Find files by extension or partial name

Find all files with an extension

To list regular files ending in .txt anywhere below the current directory, run:

find . -type f -name '*.txt'

-type f limits results to regular files rather than directories or other filesystem entries. Keep the pattern in quotes: otherwise, the shell may expand *.txt against files in the current directory before passing it to find.

Find a name containing a word

Use wildcards to match part of a basename:

find . -name '*report*'

-name tests only the entry’s basename, not its full path. A pattern containing a slash will not work as a path match; use -path when the pattern should match a path instead. See GNU’s basename pattern reference.

Rank #2
Sale
The Unix Programming Environment (Prentice-Hall Software Series)
  • The Unix Programming Environment (Prentice-Hall Software Series)
  • Product Type: ABIS_BOOK
  • Pearson

Make the search case-insensitive or limit its depth

Ignore capitalization

GNU find provides -iname for a case-insensitive basename match:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
find . -iname 'report.txt'

This GNU option may not be available in every find implementation on Unix-like systems.

Search only a few directory levels

GNU find supports -maxdepth to cap traversal. For example:

find . -maxdepth 2 -name 'report.txt'

GNU counts the starting directory as depth 0, so a maximum depth of 2 includes that directory and entries at depths 1 and 2. -maxdepth is an implementation-specific option, not a guarantee across all Unix-like systems. Details are in the GNU directory traversal documentation.

Skip a directory subtree

To avoid searching a directory such as .git, use -prune to stop descent into it:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
find . -path './.git' -prune -o -name 'report.txt' -print

The expression skips the matching .git path; otherwise, it tests for the requested name and prints matches. Be cautious about combining -prune with -delete: GNU documents that -delete implies depth-first traversal, where -prune cannot prevent descent as intended.

Process matches carefully

Run a command on each result

GNU find can pass matches to another command. The batched form runs the command with as many matched paths as practical:

find . -type f -name '*.txt' -exec command {} +

Review the match expression and results before substituting any command that changes or deletes files. GNU documents security differences between -exec and -execdir; -execdir runs the command from each matched file’s directory and requires a safe PATH containing only absolute directory names. Consult the GNU single-file command reference before using it with sensitive operations.

Pass results through a pipeline

Ordinary newline-separated output can be ambiguous when filenames contain newlines. For bulk processing, use null-delimited output and a consumer that supports it, such as xargs -0:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
find . -type f -name '*.txt' -print0 | xargs -0 command

GNU’s multiple-file processing guidance covers null-delimited output and batching.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Quick command reference

Goal Command Notes
Find an exact basename recursively find . -name 'report.txt' -name matches the basename, case-sensitively.
Find regular files by extension find . -type f -name '*.txt' Quote wildcard patterns so the shell does not expand them first.
Match without regard to case find . -iname 'report.txt' GNU option; portability varies.
Match part of a basename find . -name '*report*' Use -path for a path pattern.
Restrict traversal depth find . -maxdepth 2 -name 'report.txt' GNU option; starting path is depth 0.
Skip a subtree find . -path './.git' -prune -o -name 'report.txt' -print Do not rely on this pruning behavior with -delete.

These GNU-specific details follow the GNU Findutils 4.10.0 manual. Other Unix-like systems may ship a different implementation, so check the local find manual when an option is rejected.

Quick Recap

SaleBestseller No. 2
The Unix Programming Environment (Prentice-Hall Software Series)
The Unix Programming Environment (Prentice-Hall Software Series)
The Unix Programming Environment (Prentice-Hall Software Series); Product Type: ABIS_BOOK; Pearson
$78.11
SaleBestseller No. 3
SaleBestseller No. 4

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.