Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-04-2010, 04:37 AM   #1
Registered: Oct 2008
Posts: 34

Rep: Reputation: 17
Parse a particular string in files in particular directory and its sub-directories


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.

Old 05-04-2010, 05:30 AM   #2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
I would use the "find" command---example:

from your home directory:
find . -name "*string*"
This will find all files and directories where the name contains "string"

"man find" for details
Old 05-04-2010, 05:54 AM   #3
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,505

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
When you say in files, do you mean in the name of the file or the contents of the text based file?
Old 05-04-2010, 06:49 AM   #4
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
grep -r 'pattern' /path/of/home/dir
1 members found this post helpful.
Old 05-04-2010, 08:27 AM   #5
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,204
Blog Entries: 4

Rep: Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742
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.
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
need script to copy all files containing a certain string to a directory dc6463 Programming 21 04-18-2013 01:56 PM
Copying files and sub-directories of a directory except the directories named ".abc" sri1025 Linux - General 2 08-24-2010 08:53 AM
how many files or directories are in a Linux directory? Harmain Linux - Kernel 1 10-05-2009 01:31 PM
Count the number of files in a directory and sub-directories within that directory soumyajit.haldar Linux - Software 4 03-20-2007 06:22 AM
Change a string in all files in a directory? Randux Programming 2 05-17-2006 11:47 AM

All times are GMT -5. The time now is 12:37 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration