15

How can I find a file by its content on Linux in the command line?

For example, I want to find a file containing the word "helo" on my computer.

Gareth
  • 19,080

5 Answers5

24

Use:

grep -lir "helo" /path/to/dir
soandos
  • 24,600
  • 29
  • 105
  • 136
quanta
  • 1,168
3

You can create a file named grepall in /usr/local/bin/ with following content:

find -type f -exec grep -q $1 {} \; -print

then you can search for content by use grepall something

kockiren
  • 462
1

egrep -R "hello" /path/to/dir

1

Evil way: grep "something" */*/*

0

If you're an admin or coder, you might consider ripgrep instead of the usual grep.

rg helo for example searches all files in the current working directory (incl. subfolders).

For more detailed information, consult the guide, the man page or even the code.

mbx
  • 794