Home » How-to » How to Find File in Linux

How to Find File in Linux

In Unix operating systems and Linux all objects are files. It means that files are used not only for saving user data and system configuration, but different system management and communication mechanisms are based on files too. Therefore, searching for files is very important, and it will be very useful for beginners to learn how to find the location of a specific file, it's a program, image, or document.

There are many ways to search in Linux in the graphical interface and through the command line. In today's article, we will cover how to search for a file in Linux using all different tools. But let's start with programs that have a graphical interface.


Table of Contents

How to Find File in GUI

In popular graphical desktop environments like Gnome or KDE, file searching is supported directly in the main menu. This search is performed in real-time and only searches the home folder and a few standard subfolders, such as Documents, Downloads, etc. In addition, most file managers support searching for a file in the selected folder and its subfolders. I won't be covering this in this article. Instead, let's focus on utilities that allow for advanced file searching.

1. Catfish

This is a simple application for file searching. You can select the file type to search for, as well as the time it was modified. The application searches the entire file system, so it can take quite a while. It doesn't search in real-time, but instead uses the mlocate search index. You can install Catfish in Ubuntu using the following command:

sudo apt install catfish

After launching the program, you can immediately type the desired query in the search bar and press the search button. For example, let's search for file1:

1681479121-catfish.png

If you want to find only files modified today, select the Today item in the left side of the window. Also you can select Custom and specify the modification date range manually.

1681479153-catfish.png

Moreover, the utility supports searching by content. Simply enable the Search file contents checkbox in the settings:

1681479787-catfish.png

2. FSearch

This tool can find files by name and works similarly to the Everything Search Engine. On the first launch, you need to create a search index based on the folders which you plan to use for search. After this, you will get results immediately after entering text. Also the application supports file type modifiers, wildcard characters, AND/OR operators, regular expressions, sorting by type and size, and much more. You can find information on how to install FSearch in your distribution on the GitHub page. At the first launch, the application window looks like this:

1681479997-fsearch.png

After starting the application, you need to press the Add Folders button and add the directories for searching using the button with the plus icon:

1681480045-fsearch.png

Here you can also configure the search index parameters and its update frequency. Later, you can access index configuration settings by opening to Edit -> Preferences -> Database. After that, you can simply start typing the file name in the search bar and it will immediately appear in the list below:

1681480129-fsearch.png

You can also use a file type modifier, for example, pic: for images:

1681480170-fsearch.png

In addition, the following file type modifiers are available: file, folder, app, archive, audio, doc, video. You can also use regular expressions with the regex modifier:

1681480209-fsearch.png

If you want to search file by its size use the size modifier:

1681480235-fsearch.png

I will not describe all modifiers in this article, you can find them on this page.

There is another similar search utility called AngrySearch. However, it has not been updated for a long time, and its functionality is roughly the same as FSearch, so I will skip it.

3. Recoll

This application can also search files in Linux not only by name but also by their content. It uses the Xapian full-text search engine. You need to create a search index, as well as in the previous application. Click on the Indexing Configuration button to do it:

1681480319-recoll.png

Add all directories which you want to use for searching in the Top-Level Directories section. It creates a full-text index, so you can also connect word dictionaries for your language in the Stemming Languages section. By default, only your home folder is selected:

1681480369-recoll.png

When you complete configuration click the Ok button and then Start the indexing process button. The application offers four types of search queries:

  • Any word - at least one word from the query must be present in the name or content;
  • All words - all words from the query must be present in the name or content;
  • File name - search only by file name;
  • Query language - allows you to create complex queries using Xapian's query language.

For example, select the File Name search type and type the query to search for files by name in Linux:

1681480431-recoll.png

If you want to search by content choose Any Word, All Words, or Query Language. For example:

1681480472-recoll.png

You can filter files for searching by content by a extension or file name using the query language. The syntax is quite simple: field_name:value. For example, let's have a look, how to find all occurrences of Losst in files which names are starting with "file":

1681480500-recoll.png

More detailed information about all possible modifiers can be found in the official documentation.

How to Search Files using Command Line

While graphical utilities are designed with everyday users in mind, primarily for searching within the home folder, console programs offer much greater flexibility when it comes to searching for all types of files, including system and virtual files. These powerful tools are a go-to choice for system administrators and developers.

1. find

The most commonly used file search command in Linux at the moment is find. It has many capabilities: you can search for files by name, modification or creation date, use regular expressions and masks, perform specific actions for found files, adjust search depth, and much more.

By default, the find command searches for both files and directories. If a folder is not explicitly specified, the search will be performed in the current directory. If you want to search only files use the -type option with the f value. And you must to use the -name option to specify the query. For example:

find -type f -name "file1"
find-type-f-name-file1.png

Note, that find will find only files which exactly filename specified. If you want to find files which names contains some characters, you must use wildcard symbols. For example:

find -type f -name "file*"
find-type-f-name-file.png

If you want to specify the directory for searching, paste it in front of other options. For example, let's find all files that start with "pa" in the /etc/ folder:

sudo find /etc/ -type f -name "pa*"
sudo-find-etc-type-f-name-pa.png

If you want to ignore character case, use the -iname option instead of -name:

sudo find /etc/ -type f -iname "pa*"
sudo-find-etc-type-f-iname-pa.png

If you want to find files with a specific extension, you can do this by specifying an asterisk before the query. For example, getting all .ini files:

sudo find /etc/ -type f -name "*.ini"
sudo-find-etc-type-f-name-ini.png

Read the article find command in Linux for more information about this command.

2. fd

Fd is an alternative to the find command, written in Rust. It outperforms the original find in terms of speed, supports color output, regex search, ignores hidden files and files listed in .gitignore, and has a simpler and more user-friendly syntax. To install the utility in Ubuntu, use the following command:

sudo apt install fd-find

Please note that in Ubuntu, the command is called as fdfind. Like find, fd searches in the current folder by default, but instead of an exact name match, it expects a part of file name or a regex pattern. For example, to find all files in the current folder containing the word "file" in name, simply use the command:

fdfind file
fdfind-file.png

Next, let's have a look how to specify folder for searching. For example, use the following command, to find files with names starting with "pa" in the /etc/ folder:

sudo fdfind "^pa" /etc/
sudo-fdfind-pa-etc.png

If you need to search for files by extension, use the -e option. For example, to search for all .ini files containing the letter "x" in their names within the /etc/ folder, execute:

sudo fdfind -e ini "x" /etc/
sudo-fdfind-e-ini-x-etc.png

You can visit its GitHub page, for more detailed information about the utility.

3. fzf

The fzf command is powerful tool for fuzzy search files by names in Linux. By default it displays the list of files in the current directory and input field where you can enter your search query to filter these files. The list is filtered in real-time. Use the following command to install the program in Ubuntu:

sudo apt install fzf

Once the utility is installed, navigate to the folder where you want to perform the search. For example /etc:

cd /etc/

Now, launch the utility and enter the query "pass" to find all files with "pass" in their names:

fzf

The most relevant matches will be listed at the bottom. You can navigate the file list using the up and down arrow keys. If you want to exit, press Enter, and the path to the currently selected file will be displayed in the terminal:

If you want to search for matches only at the beginning of a file name, use the ^ symbol in the query:

And if you want to search only from the end, use the $ symbol. For more detailed information, you can read the official documentation.

4. skim

This is another real-time fuzzy search utility for Linux, written in Rust. It can do almost everything that fzf can, but it's more lightweight. The utility is not available in the official Ubuntu repositories, but you can install it using cargo:

cargo install skim

You need to navigate to the folder where the search will be performed as well as in fzf. For example:

cd /etc/

Now you can launch the program and start entering your search query:

sk

You can navigate the list of found files using the up and down arrow keys. Unlike fzf, skim supports a command mode, which allows you to add an additional layer of filtering by combining skim with grep or other utilities. Just specify the command using the -c option. For example:

sk --ansi -c 'grep -r "{}" .'

After executing the command, you'll see not only the file names but also their content. Here you can filter files by name. For example, only those containing the path "init.d":

Then, switch to command mode using Ctrl+Q and enter the query for content search:

Or you can launch sk command in the command mode by adding the -i option:

sk --ansi -i -c 'grep -r "{}" .'

5. locate

The locate command is outdated and has already been removed from many distributions. It doesn't perform real-time search like find, but rather searches a previously created index, focusing only on searching for files by their names. You enter a word that interests you, and the utility displays all known files with names containing that word. Regular expressions can be used too. For example, let's find all files with names containing "passwd":

locate passwd
locate-passwd.png

Keep in mind that if a file was added after the database was created, it won't be found. You can update the locate search index using the following command:

sudo updatedb

Searching for Files by Content in the Terminal

There are several console utilities for searching files by content in Linux, which will be described in detail in a another article. These include SilverSearcher, ripgrep, ack, and others. However, historically, the most popular and frequently used utility for searching text within files is grep. It comes pre-installed in all popular distributions and provides enough capabilities for most tasks.

If you want to find files containing a specific string, simply use the -r option and specify the folder in which to search for the text. For example, let's find all files in /etc/ that contain the line "error_reporting":

sudo grep -r "error_reporting" /etc/
sudo-grep-r-error-reporting-etc.png

The grep command is very useful for searching configuration files or checking code for malware.

How to Find the Location of a Linux Executable File

There is the whereis command that can help with it. This command is quite simple and solves only one task. It shows the location of the executable file of the specified program. For example, if you want to find out where grep is located, just run:

whereis grep
whereis-grep.png

Wrapping Up

In this article, I we have dove into how to search files in Linux using various applications in GUI and command line. As you can see, there are numerous utilities available to help you find everything. Which do you prefer? Write down in the comments section below!

Rate the Article

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...
Creative Commons License
The article is distributed under Creative Commons ShareAlike 4.0 license. Link to the source is required .

Leave a Comment