How to Find a File in Ubuntu Linux Terminal Using the find Command

When working in a graphical desktop environment, finding a misplaced document is usually as easy as typing its name into a search bar. In a Linux terminal environment, however, you must rely on command-line utilities. The find command is the undisputed king of search in Linux. It is incredibly powerful, allowing you to search not just by name, but by file size, modification date, and permissions.

The Basic Syntax of the find Command

The find command is structured very specifically. You must tell it where to start searching, and what to look for.

find [path] [options] [expression]

Finding a File by Name

The most common use case is searching for a file when you know exactly what it is called. For example, let’s say you are looking for a file named “project_report.pdf”.

If you want to search your entire computer (starting from the absolute root directory), you would type:

sudo find / -name "project_report.pdf"

Note: We use sudo here because searching the entire root directory (/) requires scanning folders that standard users do not have permission to read.

If you know the file is somewhere in your personal home folder and you don’t want to waste time searching the entire system, you can restrict the search path:

find ~ -name "project_report.pdf"

(The tilde ~ symbol represents your current user’s home directory).

Ignoring Capital Letters (-iname)

Linux is strictly case-sensitive. A search for “Report.pdf” will not find “report.pdf”. If you are unsure of the exact capitalization, use the -iname (case-insensitive name) flag instead of -name.

find ~ -iname "project_report.pdf"

Using Wildcards for Partial Matches

What if you don’t know the exact name, but you know it is a PDF file? You can use the asterisk (*) as a wildcard. The asterisk tells the command, “match any characters here.”

To find every single PDF file inside your home folder, you would type:

find ~ -name "*.pdf"

To find any file that begins with the word “invoice”, regardless of its extension, you would type:

find ~ -name "invoice*"

Silencing “Permission Denied” Errors

When searching broad directories like / or /etc, the find command will output dozens of “Permission denied” errors for folders you aren’t allowed to look inside. This can clutter your screen and hide the actual successful search results.

You can hide these errors by appending 2>/dev/null to the end of your command. This tells Linux to take all error messages (channel 2) and throw them into the digital trash can (/dev/null).

find / -name "config.yaml" 2>/dev/null

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.