LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 02-01-2014, 07:45 PM   #1
pratham29
LQ Newbie
 
Registered: Oct 2013
Posts: 8

Rep: Reputation: Disabled
Find a string on linux system


I need to find a random string. But I do not know its location on system or path or directory.
I used grep , find command but was unable to find any directory/file which had this string. Kindly help me with this.

Thanks for time and consideration.
 
Old 02-01-2014, 09:42 PM   #2
Isaac Velando
LQ Newbie
 
Registered: Feb 2014
Location: Texas
Distribution: Arch, Ubuntu Server, CentOS
Posts: 29

Rep: Reputation: 21
Could you clarify whether you're searching for a file name matching a pattern or a string contained in a file? You mentioned both find and grep and usually find is best suited for locating files whereas grep is best suited for locating strings within files.

If you're just looking for a file, my preferred way is through the mlocate program; the usage is to run sudo updatedb to update the mlocate database and run locate pattern to find files matching pattern; you can also use regular expressions here -- consult the manual with man locate for details. Alternatively, you can use the find command with syntax like:

Code:
find /path/to/top/directory/ -type f -name '*pattern*'
which matches files with pattern in their name recursively starting at /path/to/top/directory/. Alternatively you can use
Code:
find /path/to/top/directory/ -type f -regex 'regularExpressionGoesHere'
if regex is more suitable. You can also use -type d to only find directories.

If you're looking for a string within a file you definitely want to be using grep. Sample syntax might be:
Code:
grep -ir 'regularExpressionGoesHere' /path/to/top/directory/
where the options -i make the pattern case insensitive and r makes the search recursive.

If you need clarification let me know.
 
  


Reply



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
Find a string and edit only that string using sed ulto Programming 10 01-24-2014 01:44 AM
find string in filename and use string to create directories daberkow Linux - Newbie 11 05-01-2009 02:12 PM
Linux command to find and replace string within text file chips11 Linux - Newbie 5 11-24-2008 02:25 PM
find a string in all ascii file of a SOLARIS system markraem Solaris / OpenSolaris 4 01-16-2008 05:58 PM
find a string in all ASCII files of a system markraem Linux - Software 5 12-12-2007 04:08 AM

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

All times are GMT -5. The time now is 01:24 AM.

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
Open Source Consulting | Domain Registration