We have all been there. You downloaded a script, saved a configuration file, or created a log weeks ago, and now it is completely vanished into the deep directory structure of your Linux system. While graphical file managers are nice, they simply cannot match the speed and power of the command line when you need to hunt down a specific file across the entire system.

Whether you are a developer debugging a server or a beginner trying to navigate the terminal, mastering the search commands is a superpower. Here is how to find exactly what you are looking for, filtered by name, size, date, or even the text written inside the file.

⚡ Quick Cheat Sheet

If you are in a hurry, here are the three commands you will use 90% of the time:

  • Find by name: find . -name "filename.txt"
  • Find by text inside: grep -r "search_text" .
  • Find fast (indexed): locate filename

1. Finding Files by Name (The find Command)

The find command is the Swiss Army knife of Linux searching. It searches through the live file system, so it is always accurate but might take a few seconds on large disks.

The basic syntax is simple: find [where_to_look] [criteria] [what_to_find].

To find a file named app.log in the current directory and all subdirectories, use this:

find . -name "app.log"

Find a file in linux using the command line

Handling Case Sensitivity

Linux is case-sensitive by default. If you are not sure if you saved the file as Notes.txt, notes.txt, or NOTES.TXT, use the -iname flag to ignore case:

find . -iname "notes.txt"

Using Wildcards

Often, you do not remember the exact name, but you know the extension. For example, if you are looking for a Python script you wrote, you can search for everything ending in .py:

find . -name "*.py"

Or if you only remember a part of the name, put asterisks around it:

find /home -name "config"

This will return any file containing "config" in its name located in your home folder.

Pro Tip: If you are getting too many "Permission denied" errors while searching the whole system, append 2>/dev/null to the end of your command. This sends all error messages to a black hole, keeping your output clean.

2. Finding Directories Only

Sometimes you are not looking for a file, but a specific folder. The find command treats everything as a file by default, but you can filter strictly for directories using the -type d flag.

find . -type d -name "backup"

If you find a directory that you no longer need and want to clean up, make sure you know the proper way to remove directories in Linux to avoid accidental data loss. On the flip side, if you are specifically hunting for lost folders, we have a dedicated guide on how to find a directory on Linux which covers navigation tricks in more depth.

3. Finding Files Containing Specific Text (grep)

This is a lifesaver for developers. Imagine you remember writing a function called connectDatabase, but you have no idea which file it is in. You don't need to find the file name; you need to find the content.

Use grep with the -r (recursive) flag:

grep -r "connectDatabase" /var/www/html

  • -r: Search recursively.
  • -n: Show line numbers (super helpful for coding).
  • -w: Match the whole word only.
  • -l: Show only the filenames, not the snippet of text.

If you are debugging logs and need to see the live output of a file once you find it, you will likely switch to the Linux tail command immediately after.

4. Finding Files by Size (Disk Cleanup)

Is your disk full? You can use find to locate massive files that are eating up your storage. This is essential for server maintenance.

To find files larger than 100MB in the current directory:

find . -type f -size +100M

You can also find files within a specific range, for example, between 50MB and 100MB:

find . -type f -size +50M -size -100M

If you are running a Windows subsystem and dealing with disk space issues, understanding how your environment is set up is key, especially if you had to install WSL2 on Windows manually.

5. Finding Files by Time (Modified Date)

If you know you worked on a file yesterday but completely forgot its name, searching by time is the best strategy.

  • Files modified in the last 24 hours: find . -mtime -1
  • Files modified exactly 7 days ago: find . -mtime 7
  • Files modified more than 30 days ago: find . -mtime +30

This is particularly useful for finding log files that were updated recently or clearing out old backups.

6. The Faster Alternative: locate

While find walks through the file system in real-time, locate searches a pre-built database. This makes it instant, but it might not see files you just created 5 minutes ago.

To use it, you might need to install it first:

sudo apt install mlocate

Then, ensure the database is up to date:

sudo updatedb

Now, searching is lightning fast:

locate my_secret_file.txt

This command is great for system files that do not change often. However, for recently created work, stick to find or checking your recently active paths if you are dealing with specific shell configurations like zsh command not found errors.

Which Command Should I Use?

  • Use locate when you want instant results for system files.
  • Use find when you need precision, recent files, or advanced filters (size, permissions, user).
  • Use grep when you forgot the filename but remember what is written inside it.