Featured Article

"How to Search for Files in Linux: A Comprehensive Guide"

Alan Jun 16, 2026

In the Linux universe, finding files can be a breeze or a challenge, depending on your familiarity with the command line. This guide will walk you through various methods to search for files in Linux, making your file management tasks more efficient.

find – Locate Files and Directories in Linux
find – Locate Files and Directories in Linux

Understanding the Linux File System

How to Search for a file in Linux
How to Search for a file in Linux

Before we dive into searching for files, it's essential to understand the Linux file system hierarchy. The root directory, denoted by a forward slash (/), is the starting point. From here, you'll find directories like /home, /usr, /var, and /etc. Each directory contains files and subdirectories, creating a tree-like structure.

Basic File Searching with 'find' Command

Using find, locate, which and whereis Commands to Search for Files in Linux - Make Tech Easier
Using find, locate, which and whereis Commands to Search for Files in Linux - Make Tech Easier

The 'find' command is a powerful tool for locating files and directories. Here's the basic syntax:

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

Replace '/path/to/search' with the directory you want to start the search from, and 'filename' with the name of the file you're looking for. The '-name' flag searches for files based on their names. For example:

How to Use FSearch to Quickly Search Files in Linux - Make Tech Easier
How to Use FSearch to Quickly Search Files in Linux - Make Tech Easier

find /home -name "example.txt"

This command will search for a file named 'example.txt' in the '/home' directory and its subdirectories.

Using Wildcards and Regular Expressions

You can use wildcards (*) and regular expressions to search for files with specific patterns. For instance, to find all Python scripts in your home directory, you can use:

Khalil Afridi on X
Khalil Afridi on X

find ~/ -name "*.py"

And to find files starting with 'log' and ending with '.txt', you can use:

find /var -regex ".*/log.*\.txt"

Searching with 'locate' Command

The 'locate' command is faster than 'find' as it searches a database of files on your system. However, the database is updated only periodically, so it might not show recently created or deleted files. Here's how to use it:

Searching for Files with the find Command
Searching for Files with the find Command

locate "filename"

To make 'locate' work faster, you can update its database with the 'mlocate' command:

sudo mlocate

Searching with 'whereis' and 'which' Commands

ANGRYsearch - Quick Search GUI Tool for Linux
ANGRYsearch - Quick Search GUI Tool for Linux
the screenshote view of an internet webpage with many different types of information
the screenshote view of an internet webpage with many different types of information
Learn Linux from Beginner to Advanced (Part 23) – File Search Advanced
Learn Linux from Beginner to Advanced (Part 23) – File Search Advanced
Linux File System Explained – Complete FHS Directory Guide
Linux File System Explained – Complete FHS Directory Guide
Learn Linux from Beginner to Advanced (Part-6) | Compression & Search Commands
Learn Linux from Beginner to Advanced (Part-6) | Compression & Search Commands
🔗 ln – Create Link to File and Directory in Linux
🔗 ln – Create Link to File and Directory in Linux
Linux File System
Linux File System
the linux file system diagram is shown in this graphic style, with several different types of data
the linux file system diagram is shown in this graphic style, with several different types of data
Learn how to copy a directory on Linux
Learn how to copy a directory on Linux
Linux File System
Linux File System
the linux file system is shown in this diagram, which shows how to use it
the linux file system is shown in this diagram, which shows how to use it
the linux file system is shown in this screenshote, which shows how to use it
the linux file system is shown in this screenshote, which shows how to use it
the linux file permision chart is shown in this screenshote, which shows how
the linux file permision chart is shown in this screenshote, which shows how
Linux Day 2 | File Operations Cheat Sheet for Beginners
Linux Day 2 | File Operations Cheat Sheet for Beginners
the linux file system is shown with numbers and symbols in each column, which are labeled
the linux file system is shown with numbers and symbols in each column, which are labeled
Quick Linux Tip : List Attributes of Files and Directories
Quick Linux Tip : List Attributes of Files and Directories
a screenshot of the linux finder
a screenshot of the linux finder
Learn Linux from Beginner to Advanced (Part-3) | File Viewing & Text Commands Cheat Sheet
Learn Linux from Beginner to Advanced (Part-3) | File Viewing & Text Commands Cheat Sheet
the linux file extensions menu is shown in this screenshote image, which shows an array of options
the linux file extensions menu is shown in this screenshote image, which shows an array of options

The 'whereis' and 'which' commands are useful when searching for executable files. 'whereis' searches for the source code, binary, and manual page files, while 'which' only shows the full path of the executable.

whereis ls
which ls

Searching File Content with 'grep' Command

The 'grep' command allows you to search for files containing specific text. Here's the basic syntax:

grep -r "search-term" /path/to/search

The '-r' flag enables recursive search in subdirectories. For example, to find all files containing the term 'error' in the '/var/log' directory, you can use:

grep -r "error" /var/log

Using 'grep' with Regular Expressions

You can also use regular expressions with 'grep' to search for more complex patterns. For instance, to find all lines containing a number followed by 'error', you can use:

grep -r "[0-9]*error" /var/log

Conclusion

Mastering these commands will significantly improve your productivity when working with Linux. Whether you're looking for a specific file, searching for content within files, or trying to locate an executable, these tools have got you covered.