How do I find a file by name in Linux?

Updated October 2026 · How we answer

Short answerUse find /path -name "filename" to search by name, or locate filename for a faster index-based search.

Using find for precise searches

find searches a directory tree in real time. The basic syntax is find [path] [options] [expression]. To find by name, use -name (case-sensitive) or -iname (case-insensitive). For example, find /home -name "*.txt" finds all .txt files under /home.

You can combine with -type f for files or -type d for directories. To execute a command on each result, use -exec. For example, find . -name "*.log" -exec rm {} \; deletes all .log files in the current directory tree.

  • find / -name "myfile.txt" 2>/dev/null — search entire system, suppress errors
  • find . -iname "*.jpg" — case-insensitive search
  • find /var -type f -name "*.conf" — only files
  • find /tmp -type d -name "cache" — only directories
  • find . -name "*.tmp" -delete — find and delete

Using locate for speed

locate uses a prebuilt database (updated by updatedb) and returns results almost instantly. It's faster than find but may be out of date. Run sudo updatedb first if the database is stale. locate supports basic patterns and -i for case-insensitive.

If locate is not installed, install mlocate or plocate. For most day-to-day searches, locate is convenient, but find is more accurate and flexible.

Common mistakes

  • Forgetting to quote wildcards: without quotes, the shell expands *.txt before find sees it, leading to unexpected results.
  • Running find / without 2>/dev/null: permission errors clutter the output.
  • Assuming locate is always up to date: it relies on a database that may be days old.
From our shopsCASEONYX: Dark-luxe tough phone cases.