Home > Operation and Maintenance > Linux Operation and Maintenance > How to find all files containing a string in Linux

How to find all files containing a string in Linux

不言
Release: 2019-02-28 10:16:30
Original
6425 people have browsed it

How to find all files containing a string in How to find all files containing a string in Linux? This article will explain about recursively searching all files containing a specific text string. The "find" command is used in the article to search for strings in files. Alternatively, you can use the grep command to search for text. Let’s look at the specific content below.

How to find all files containing a string in Linux

First let’s look at the command

#find / -exec grep -l“string-to-search”{};
Copy after login

Let’s look at the specific usage

The following is an example command for searching/ Text 'redhat' in filesystem. This command will search for all files containing the string 'redhat' and the list file name as shown below.

# find / -exec grep -l“redhat”{}; 

/lib64/security/pam_oddjob_mkhomedir.so 
/lib64/libdevmapper.a.1.02 
/lib64/libdevmapper-event.a.1.02 
/lib64/libdevmapper.a 
/lib64/libdevmapper-event.a 
...
Copy after login

Search within files with a specific file extension. Like just searching for 'redhat' in all php files, use the following command.

# find / -name'* .php'-exec grep -l“redhat”{}; 
/var/www/projects/index.php 
/var/www/projects/new.php 
...
Copy after login

This article has ended here. For more other exciting content, you can pay attention to the relevant column tutorials on the php Chinese website! ! !

The above is the detailed content of How to find all files containing a string in Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template