top of page
  • Writer's pictureArun Kumar

Shell Script to Find Text Files Containing Word 'user_defind'

Linux shell script allows user to find the word containing in files in a directory. In order to achieve this, we are using the find and grep command. Here the user will be asked to enter the text to search.

# !/bin/bash
echo "Type the word to find text files"
read fn
find . -exec grep -l "$fn" {} \;

Here is the sample output of the above script

Shell Script to Find Text Files - search in

More ways to use find and grep

  • You can select only those lines containing matches that form whole words using the -w option.

  • You can also use this to search for two or more words - egrep -w -R 'word1|word2' ~/projects/


Recent Posts

See All
bottom of page