Tutorial2026-11-089 min read

How to Find a File by Name in Linux: find, locate and fd

To find a file by name in Linux, use find with a starting directory and -name: find /home -name "report.pdf". find searches recursively through every subdirectory by default. Use -iname instead of -name to ignore upper and lower case, and wrap wildcards in quotes: find . -iname "*.pdf".

find checks the disk live, so it always sees the current files but can be slow on big trees. For instant results across the whole system, locate (on modern distributions, plocate) searches a prebuilt index, and fd is a faster, friendlier find alternative. All three are covered below, along with the quoting and permission problems that make searches fail.

The commands were tested with GNU findutils 4.9 (the find on Ubuntu 24.04 and Debian 12), plocate 1.1 and fd 10. Output paths are examples.

The basic find command

The form is find WHERE -name WHAT:

find ~/Documents -name "report.pdf"

This starts in ~/Documents, walks every subdirectory below it, and prints the path of every entry named exactly report.pdf:

/home/sam/Documents/report.pdf
/home/sam/Documents/2025/q4/report.pdf

The starting point can be any directory:

  • . searches the current directory and everything under it.
  • ~ searches your home directory.
  • / searches the whole system (see the permission errors section below).

You can give several starting points at once: find ~/Documents ~/Downloads -name "report.pdf".

Ignore case with -iname

-name is case-sensitive, because Linux file names are. -name "report.pdf" will not match Report.PDF. Use -iname when you don't know the capitalisation:

find . -iname "report.pdf"

Search with wildcards (and why you must quote them)

-name and -iname accept shell-style wildcards:

  • * matches any number of characters: "*.pdf" matches every PDF.
  • ? matches exactly one character: "IMG_000?.jpg" matches IMG_0001.jpg to IMG_0009.jpg.
  • [...] matches one character from a set: "report-[0-9].txt".

Find all PDFs below the current directory, any case:

find . -iname "*.pdf"

Find anything with "invoice" anywhere in the name:

find ~ -iname "*invoice*"

Always put the pattern in quotes. Without quotes, the shell expands *.pdf against the current directory before find ever sees it. If the current directory holds one PDF, find silently searches for that one name; if it holds two, you get an error like this:

find: paths must precede expression: `report.pdf'
find: possible unquoted pattern after predicate `-name'?

Single or double quotes both work for patterns. Quotes also handle names with spaces: find . -name "meeting notes.txt".

Note that -name only looks at the file name itself, not the directories above it. To match against the full path, use -path, for example find . -path "*/invoices/*.pdf".

Find only files or only directories

By default find matches files, directories, links and everything else. Narrow it with -type:

  • -type f for regular files
  • -type d for directories
  • -type l for symbolic links
find ~ -type d -iname "reports"
find ~ -type f -iname "report*"

The order of options matters for speed but not for results here; putting -type before -name is a common habit.

Limit how deep find searches

find is recursive by default, which is usually what you want ("linux find file by name recursively" needs no extra flag). To stop it from going too deep, use -maxdepth:

find . -maxdepth 1 -name "*.pdf"

-maxdepth 1 only looks in the starting directory itself; -maxdepth 2 adds one level of subdirectories. -mindepth 2 does the opposite and skips the top level. Put -maxdepth before the tests, or GNU find prints a warning.

Hide "Permission denied" errors

Searching from / as a normal user produces a flood of errors for directories you can't read:

find: '/root': Permission denied
find: '/proc/1/task/1/fd': Permission denied

Send the error stream to /dev/null to see only the matches:

find / -name "nginx.conf" 2>/dev/null

2> redirects standard error, the stream find uses for these messages, and the results still print normally. Note this also hides real errors, such as a mistyped starting directory. If you need to search directories you can't read, run it with sudo.

More useful find combinations

Several names at once, grouped with escaped parentheses and -o (or):

find . -type f \( -iname "*.pdf" -o -iname "*.docx" \)

Exclude a directory from the results:

find . -iname "*report*" -not -path "*/node_modules/*"

Only files changed in the last 60 minutes, or the last 7 days:

find ~ -type f -iname "*.md" -mmin -60
find ~ -type f -iname "*.md" -mtime -7

Stop after the first match, which is much faster when you know there is only one:

find / -name "nginx.conf" -print -quit 2>/dev/null

Show size, permissions and dates for each match:

find . -iname "*.pdf" -ls

Match the full path with a regular expression (GNU find uses Emacs-style regex by default; -iregex ignores case):

find . -regex '.*/report\.[a-z]+'

Run a command on every match. With + at the end, find passes many files to one command:

find . -type f -iname "*.log" -exec ls -lh {} +

If what you actually want is to rename the files you found, find can do that too; the Linux rename guide has tested find ... -exec rename recipes.

Find files instantly with locate (plocate)

find reads the disk every time. locate instead searches a database of file names that is rebuilt periodically, so it answers in a fraction of a second even across the whole system. On Ubuntu 22.04 and later, Debian 12 and Fedora, the implementation is plocate, which also answers to the locate command. If it's missing, install it with sudo apt install plocate (Debian and Ubuntu) or sudo dnf install plocate (Fedora).

locate report.pdf

By default it matches the text anywhere in the full path, so locate report also returns everything inside a folder called reports. Useful options:

  • -i ignores case: locate -i report.pdf
  • -b matches only the base name (the last part of the path). locate -b '\report.pdf' finds only files named exactly report.pdf; the leading backslash turns off the implicit wildcards.
  • -c prints only the number of matches.
  • -e only shows files that still exist.
  • -l 10 stops after 10 results.
  • -r uses a regular expression: locate -r 'report\.pdf$'.

The catch is freshness. A file you created five minutes ago won't show up until the database is updated, which a system timer usually does daily. Update it by hand when you need to:

sudo updatedb
locate new-report.pdf

Use locate for "where on this machine is that file?" and find when the file is new or you need filters like type, size or date.

Find files with fd

fd is a modern replacement for the common find use cases. It is recursive by default, colours its output, skips hidden files and anything in .gitignore, and is fast. Install it with sudo apt install fd-find on Debian and Ubuntu, where the command is called fdfind because of a name clash; on Fedora and Arch the package and command are fd.

fd report

This lists every file and directory below the current one whose name contains "report". A few things work differently from find:

  • The pattern is a regular expression and matches anywhere in the name, so you don't need * around it. Use -g for a glob: fd -g "report*.pdf".
  • Smart case: an all-lowercase pattern ignores case; a pattern with a capital letter is case-sensitive. Force either with -i or -s.
  • Hidden and ignored files are skipped: add -H for hidden files and -I to include files listed in .gitignore.

Other common forms:

fd -e pdf                 # every file with the .pdf extension
fd -t d reports           # directories only
fd report ~/Documents     # search a specific directory

Find a file by name without the terminal

Every major Linux desktop has file search built in:

  • GNOME Files (Nautilus): press Ctrl+F or just start typing in a folder, and it searches that folder and its subfolders. The Activities overview (press the Super key and type) also searches indexed files in your home directory.
  • KDE Dolphin: press Ctrl+F to open the search bar, with options to search from the current folder or everywhere. KDE's Baloo indexer powers the instant results in KRunner and the application launcher.
  • Xfce Thunar: recent versions support Ctrl+F search; Catfish is a standalone search tool often installed alongside it.

Desktop search usually covers only your home directory and indexed locations; for system files, use find or locate.

A note for macOS users

macOS ships the BSD version of find. The everyday options in this guide (-name, -iname, -type, -maxdepth, 2>/dev/null) work the same way there, but some GNU extensions and the default regex syntax differ, so check man find before relying on advanced options. On a Mac, mdfind -name report.pdf queries the Spotlight index and is usually the fastest option.

Once you've found the files

Finding badly named files is often the first step to fixing them. The Linux rename guide covers mv, rename and bulk loops, and our regex rename guide explains patterns in depth. If the problem is that names like scan0042.pdf say nothing about the contents, File Renamer AI reads each document or photo and suggests a descriptive name, which also makes the next search much easier.

Frequently Asked Questions

How do I find a file by name in Linux?

Run find with a starting directory and the name: find /home -name "report.pdf". It searches all subdirectories automatically. Use -iname instead of -name to ignore case, and quote wildcard patterns such as "*.pdf".

How do I search for a file recursively in Linux?

find is recursive by default, so find . -name "notes.txt" already searches the current directory and every folder below it. Use -maxdepth to limit how deep it goes, for example find . -maxdepth 2 -name "notes.txt".

How do I find a file by partial name?

Put wildcards around the part you know and quote the pattern: find ~ -iname "*invoice*". With locate, a plain word already matches anywhere in the path: locate -i invoice. With fd, fd invoice matches anywhere in the name.

How do I hide Permission denied errors in find?

Redirect the error stream to /dev/null by adding 2>/dev/null to the end of the command, for example find / -name "nginx.conf" 2>/dev/null. The matches still print. Use sudo if you need to search directories your user can't read.

Why doesn't locate find my file?

locate searches a database that is usually rebuilt once a day, so new files are missing until it is updated. Run sudo updatedb and try again. If the file is in a location excluded from indexing, or on a removable drive, use find instead.

What is the difference between find and locate?

find walks the directories live every time, so it is always current and supports filters like type, size and modification time, but it is slower. locate searches a prebuilt index of file names, so it is nearly instant but can miss files created since the last index update.

Ready to organize your files?

Try AI renaming right away. No sign-up needed until you download.

Try It Free