How to Find a File Containing a "Keyword" in Linux?


How to find a file containing a "keyword" in linux?

To find files which contain a specific word you can use below commands.

Login to Linux server and open a terminal (Applications >> Accessories >> Terminal).

1. 'Find' command

find -name "*pattern*"

It displayed all the files which have the word "pattern" in the filename.

find /home -name "*pattern*"

This will look for the files in the /home directory with "pattern" in the filename.


2. 'Grep' command

grep -H -r "pattern" folder_name

-H : Print the filename for each match.

-r : Read all files under each directory, recursively.

eg: grep -H -r "pattern" /home

This will look for the files in the /home directory with "pattern" in the filename.

Last update:
2016-06-16 01:54
Author:
Sherin George
Revision:
1.1
Average rating:0 (0 Votes)

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.

Records in this category

Tags

top