Browse tutorial categories
On this page

Find Files by Name on Linux

Use the find command to search a directory tree by filename, limit the search area, and inspect results before taking action.

The find command searches directory trees and can filter results by properties such as name, type, and modification time. Start with a narrow directory and print matches before performing any operation on them.

Search by exact name

find ./project -type f -name "config.json" -print

This searches only files beneath ./project. Use -iname instead of -name when case should not matter.

Search with a pattern

find ./downloads -type f -iname "*.pdf" -print

Quote wildcard patterns so the shell passes them to find rather than expanding them in the current directory first.

Review before changing files

For a read-only list, -print is sufficient. If planning to delete or modify matching files, inspect the output first and use a command appropriate for the file names. Do not run broad destructive actions against / or an unverified directory.

Limit search depth

find ./project -maxdepth 2 -type f -name "*.md" -print

-maxdepth can make results easier to review in a large tree. Check your system’s find manual for platform-specific options.

#Linux#command line#files