Monday, May 7, 2012

Finding a text in files in linux

To search for a text in a bunch of files in a directory in Linux use grep command recursively as below:

$ grep -irn "text" /home/ai 

This will search for the word "text" in all files in home directory and all sub directories.

The -i asks it to ignore case.
The -r lets grep dig into the directory and all sub-directories recursively.
The -n outputs the line number when the match is found.
  

No comments:

Post a Comment