Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find a file containing specific text in Centos7?

Tags:

linux

centos7

I have a server which runs on centos 7. I need to find a file containing 0774386850 so that I can replace with another string. Kindly give me a Linux command to give me that file

like image 654
Peter Mutai Avatar asked Aug 07 '17 10:08

Peter Mutai


People also ask

How do I find all files containing specific text?

Without a doubt, grep is the best command to search a file (or files) for a specific text. By default, it returns all the lines of a file that contain a certain string. This behavior can be changed with the -l option, which instructs grep to only return the file names that contain the specified text.

How do I search for a file with a specific content in Linux?

You can use grep tool to search recursively the current folder, like: grep -r "class foo" . Alternatively, use ripgrep .

How do I search for a word in CentOS 7?

This tutorial uses the 'grep' command to search for strings in files. Alternatively, you may use the find command to look for files with specific content. The grep command offers other useful options for finding specific text in file systems. --exclude-dir=PATTERN : directories that match PATTERN will be skipped.

How do I find a specific word in a file in Linux?

The grep command searches through the file, looking for matches to the pattern specified. To use it type grep , then the pattern we're searching for and finally the name of the file (or files) we're searching in. The output is the three lines in the file that contain the letters 'not'.


1 Answers

By using grep command, you can achieve what you expected

grep -rlnw '/path/to/somewhere/' -e '0774386850'
-r or -R is recursive,
-n is line number, and
-w stands for match the whole word.
-l (lower-case L) file name of matching files.
like image 161
ntshetty Avatar answered Oct 23 '22 17:10

ntshetty