Linux is a powerful operating system that is designed to work with files and data. An important task for Linux users is to search for specific files based on their contents. This may be needed, for example, to find a lost document or file with important information.

In this article we will look at several ways to perform this task and give practical advice on how to make the search as convenient and ideal for you as possible.

Find a Special File with GREP command

What is the grep command? For your information, it is one of the most powerful text search commands in Linux. You can use it to search a file based on keywords in its content. Here is an example of use:

grep -rnw '/path/to/your/directory/' -e 'your_search_text'

Here we will look carefully at what each name means:

-r means recursive search in subdirectories.

-n prints the line numbers of matches.

-w excludes partial matches (whole words only).

-e specifies the search text.

/path/to/your/directory/‘ is the initial path from which the search begins.


Or, for example, you want to find in the /user/games folder containing the string “test1”. The output will be as follows:

grep -r "test1" /user/games

Global Search Examples

Let’s say you want to detect files in the /etc folder and its subfolders that contain the word “network”. The output will be like this:

Optional Features

The grep command can use various options to customize the search:

-c – print only the number of lines containing the required information

-v – search for lines that do not contain the required information.

-i – ignore case of characters when searching

-n – display line numbers containing the required information

Find command – Search by title and content

The ability to quickly and efficiently find the information you need in an operating system is a critical skill. Sure, modern file managers provide excellent tools for searching files, but searching in the Linux terminal provides much more power and flexibility. In the Linux terminal, you can search not only by file name, but also by its creation date, content, and use regular expressions to precisely find the data you need.

The find command can also be used to search for files based on content. An example will be provided below:

find /path/to/your/directory/ -type f -exec grep -l 'your_search_special_text' {} \;

The find utility is built into all Linux distributions by default, and you won’t need to store any additional packages. This is a real treasure for those who want to get the most out of command text.

/path/to/your//directory/ is the starting path for the search.

-type f means search only for files (not directories).

-exec executes a grep command for each file found.

your_search_special_text‘ is the search text.

The find command in Linux is a very powerful tool for searching files and allows you to perform a variety of filtering and processing operations on search results.