LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Parse a particular string in files in particular directory and its sub-directories (https://www.linuxquestions.org/questions/linux-newbie-8/parse-a-particular-string-in-files-in-particular-directory-and-its-sub-directories-805800/)

rajivdp 05-04-2010 04:37 AM

Parse a particular string in files in particular directory and its sub-directories
 
Hi

I want linux command to parse a particular string or pattern in files that are in my home directory and its sub-directory.

Thanks in Advance.

Regards
Rajiv

pixellany 05-04-2010 05:30 AM

I would use the "find" command---example:

from your home directory:
Code:

find . -name "*string*"
This will find all files and directories where the name contains "string"

"man find" for details

grail 05-04-2010 05:54 AM

When you say in files, do you mean in the name of the file or the contents of the text based file?

PMP 05-04-2010 06:49 AM

Code:

grep -r 'pattern' /path/of/home/dir

sundialsvcs 05-04-2010 08:27 AM

To elaborate:
  • The find command does a recursive search for file names.
  • The locate command does a similar thing, faster, because it uses a pre-built index file.
  • The grep command searches for file content, and the "-r" option makes it do so recursively.


All times are GMT -5. The time now is 06:43 PM.