Bash - find file name by containing text

9 points
Created by:

In this example, we would like to show how in Bash find files that contain some specific text.

Quick solution (run in the command line):

grep -r -F "text to find" /path/to/directory

# or

grep -rl -F "text to find" /path/to/directory


  • -r means recursive searching,
  • -l means listing file names only (without found text),
  • -F means simple string mode searching,
  • /path/to/directory indicates searched directory
    (can be removed to search current directory, e.g. grep -r -F "text to find").


  • to use case insensitive execute with -i parameter:
    grep -ri -F "text to find" /path/to/directory
  • older grep versions may do not support -r parameter.

Practical example

As a practical example, we would like to show looking for org string inside ~/test directory with line  printing that contains the string.

Console preview:

$ grep -r -F "org" ~/test/
/home/john/test/sub-test/test-2.txt:Some organisation ....
/home/john/test/search.txt:organic search: 79%

Preety version:

Found fileFound line
/home/john/test/sub-test/test-2.txtSome organisation ....
/home/john/test/search.txtorganic search: 79%
Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé