How to Find a File in Linux (find command)

If you have misplaced a crucial configuration file on a headless Linux server, you cannot simply open a graphical folder and click a magnifying glass icon to search for it. You must rely on the command line.

While the grep command is famous for searching for specific words inside of files, it is the find command that you use when you are looking for the actual file itself. The find command is arguably one of the most powerful utilities in the entire Linux ecosystem, allowing you to search your entire hard drive not just by name, but by file size, modification date, and ownership.

The Basic Syntax: Searching by Name

The standard structure of the find command requires three pieces of information: the command itself, the directory you want to start searching in, and the specific criteria (like the name) you are looking for.

find /path/to/search/ -name "filename.txt"

For example, if you know you lost a file named apache.conf somewhere inside the massive /etc/ directory, you would type:

find /etc/ -name "apache.conf"

The command will instantly dive into the /etc/ folder, recursively scan every single sub-folder inside it, and print the exact, absolute file path when it locates the file (e.g., /etc/apache2/apache.conf).

How to Search the Entire Computer

If you have absolutely no idea where the file is located on your hard drive, you can tell the command to start searching from the absolute root of the file system (represented by a single forward slash /).

sudo find / -name "lost_password.txt"

(Note: You should use sudo when searching the root directory to ensure the command has the security privileges to peer inside hidden system folders).

Searching with Wildcards (When You Don’t Know the Exact Name)

If you know the file is an image, but you can’t remember if you named it “vacation_photo.jpg” or “beach_photo.jpg”, you can use the asterisk (*) wildcard symbol to search for file extensions.

find ~/Documents/ -name "*.jpg"

This command tells Linux: “Search my Documents folder and print a list of every single file that ends in .jpg, regardless of what the first half of the name is.”

Advanced Search Criteria (Size and Time)

The true power of the find command is that it isn’t restricted to just names. You can use it to hunt down massive files that are hogging your storage space, or files that were recently modified by a hacker.

Searching by File Size (-size)

If your hard drive is suddenly full and you want to locate every massive video file or bloated log file larger than 500 Megabytes, use the -size flag.

find / -size +500M

The + symbol means “greater than”. (You can also use - for “less than”, or use G for Gigabytes).

Searching by Modification Date (-mtime)

If a website configuration broke sometime in the last 48 hours, but you don’t know which specific file was edited, you can ask Linux to show you every file that was modified recently using the -mtime (modification time) flag.

find /etc/ -mtime -2

The -2 tells the command to only return files that were changed in the last 2 days. This acts as a surgical troubleshooting tool, instantly isolating the exact files that someone tampered with right before the server crashed.

Get the best tech tips delivered straight to your inbox.

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