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 02-01-2014, 08:45 PM   #1
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, 10: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:

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
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:
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.


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

All times are GMT -5. The time now is 01:41 PM.

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