Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix command to search for text string in all files

How do I get unix to search inside ALL files for a the string "hello"?

I've tried the following but it doesn't work:

sudo grep "hello" | find / -name "*" 2>/dev/null

Does anyone have any other ideas?

Thank you.

like image 401
MorganR Avatar asked Jun 25 '12 10:06

MorganR


People also ask

How do you find a string in all files in a directory Linux?

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

How do you search for a word in all files in Linux?

If you want to search multiple files, just append as many to the command as you'd like. You can also use wildcards in the commmand. The output from grep shows us which files the string was found in. To search recursively, use the -r option with grep .

How do I find all files containing specific text on Linux?

Grep Command. grep is a built-in Linux command that prints lines that match a given pattern. It returns all the lines of a file that contain a certain string by default, and the command is also case-sensitive.


1 Answers

Maybe this one?

sudo cd / && grep -rn "hello" *

EDIT: the 'n' option of course is not needed - it simply displays the line numbers and I find it nice. The 'r' option tells grep to perform recursive search within directories.

like image 157
Ivaylo Strandjev Avatar answered Oct 22 '22 08:10

Ivaylo Strandjev