News
Seven days of Black Friday madness — great deal from Serverspace!
Serverspace Black Friday
RF
August 17, 2023
Updated August 15, 2023

How To Find Files by Content in Linux

Debian Linux VPS

Introduction

Managing tasks in Linux might initially seem challenging due to several factors inherent to the operating system's design and philosophy. While Linux offers incredible power and flexibility, its unique characteristics can contribute to a perception of complexity for newcomers:

  • Command Line Emphasis: Linux relies heavily on the command line for system management. While this offers powerful control, it can be intimidating for those more accustomed to graphical interfaces;
  • Learning Curve: The command line interface requires learning specific commands, options, and syntax. This learning curve can deter users who are not familiar with these commands;
  • Diverse Distribution Landscape: Linux comes in various distributions (distros), each with its package management, configuration files, and software repositories. This diversity can lead to confusion when switching between distros;
  • Manual Configuration: Many tasks in Linux require manual configuration through text files. While this offers fine-tuned control, it can be overwhelming for those used to automated settings;
  • Dependency Management: Installing software sometimes involves resolving dependencies, which are other packages required for the software to work. This can be complex, especially for complex applications.

However, it's important to note that the perceived difficulty of Linux management diminishes as users become familiar with the system. Many resources, tutorials, and communities are available to help users learn and navigate Linux effectively. Additionally, the command line offers efficiency and precision once commands are learned. While Linux might seem challenging initially, it becomes highly rewarding as users gain confidence and experience in managing the system. Also for more simplicity manage there is utilities for find needed data by command!

Requirements

  • Root rights;
  • Debian 11 or higher version;
  • Several knowledge about work OS ;
  • Internet connection.

Installation

First of all we need to update all packages in the system and install them:

apt update && apt upgrade -y
Update OS
Screenshot №1 — Update OS

For our purpose we will use grep utility that can help scale up broad and range of our option. For search needed information we will use various of attributes. By the default we already have that utilities in our repositories or installed in our operating system, check by typing commands below:

grep --help
help
Screenshot №2 — Help

If you will see options for command then you have installed there before, now we can use utility grep in single way. For that type command below:

grep -r "tt" /etc

The system will search through the /etc directory and its subdirectories for occurrences of the string "tt" in any files. If any matches are found, the corresponding lines containing the "tt" pattern will be displayed in the terminal as output.

Please note that searching through system directories like /etc might require administrative privileges, so you might need to use the command with elevated permissions (using sudo) depending on your system configuration.

grep -v "tt" /root/sometextfile.txt

In that combination of options we match whole words only, / meaning root directory and -name have sense looking for format and name. Also we can use invert request, just type -v option for searching all content exclude pattern and option -l displayed the names of files which contains the pattern:

grep -w -r "tt" /

We can use that while we searching amount file of content apt list for example:

apt list | grep nginx

In our case sign | means pipe or operator that give output from first to the second command as argument:

Search by grep
Screenshot №3 — Search by grep

As the result we can see file with mentions nginx in the header of files or if we use option with exact match of searching word:

apt list | grep -w nginx
Exact word for search
Screenshot №4 — Exact word for search

Conclusion

Linux provides many different utilities for working with system modules, one of which we have reviewed in this article. Using the syntax and the above options, you will be able to search for and more efficiently perform the tasks assigned to you when working with files.

Vote:
5 out of 5
Аverage rating : 5
Rated by: 1
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
ITGLOBAL.COM NL
700 300

You might also like...

We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.