LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: 17
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
 
Old 05-04-2010, 06:30 AM   #2
pixellany
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:
Code:
find . -name "*string*"
This will find all files and directories where the name contains "string"

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

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
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, 07:49 AM   #4
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

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

Rep: Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028
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.
  


Reply


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 02:56 PM
Copying files and sub-directories of a directory except the directories named ".abc" sri1025 Linux - General 2 08-24-2010 09:53 AM
how many files or directories are in a Linux directory? Harmain Linux - Kernel 1 10-05-2009 02:31 PM
Count the number of files in a directory and sub-directories within that directory soumyajit.haldar Linux - Software 4 03-20-2007 07:22 AM
Change a string in all files in a directory? Randux Programming 2 05-17-2006 12:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:56 PM.

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