LinuxQuestions.org
Visit Jeremy's Blog.
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 08-08-2018, 05:05 PM   #1
vysero
Member
 
Registered: May 2018
Posts: 137

Rep: Reputation: Disabled
How to search my entire computer to see instances of a phrase?


Let's say I want to view all files where the string TipSelector is used. How might I go about doing that?
 
Old 08-08-2018, 08:06 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ArcoLinux
Posts: 9,139

Rep: Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939
Code:
grep -rwn /path -e search pattern
command line of course. Don't forget quotes " " for patterns with spaces.
 
1 members found this post helpful.
Old 08-08-2018, 08:43 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 19,217

Rep: Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926
Do you mean only text files or any string matching that on the disk?

Python could do a search for that string I think. I forgot most of it ....
 
Old 08-08-2018, 11:46 PM   #4
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,166
Blog Entries: 3

Rep: Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061
If they are plain text files, then grep as mentioned above will work. Though it can be slow for large numbers of files.

If you are dealing with a mixed variety of formats, then you'll want to index them using recoll or similar utility so that you can search quickly. Such programs are not all that hard to write in python or perl but it is quite time consuming to track down all the right parsers and filters to extract and index just the text. Then there would be building the UI after that to interface with the index. So if you're in a hurry or not interested at the moment in programming, I'd recommend just using recoll.

Others to compare would be Baloo, or Tracker. Strigi was ok too but seems to have been abandoned, as have several others.
 
Old 08-09-2018, 01:29 AM   #5
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,513

Rep: Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004
Searching every file on the system could take hours. Do you have any idea what type of file your looking for?
 
1 members found this post helpful.
Old 08-09-2018, 01:43 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,081

Rep: Reputation: 4137Reputation: 4137Reputation: 4137Reputation: 4137Reputation: 4137Reputation: 4137Reputation: 4137Reputation: 4137Reputation: 4137Reputation: 4137Reputation: 4137
I think the correct answer is: you don't want to do that.
Linux maps everything into filesystem entries, therefore a simple recursive grep on / will scan all your hardware, processes and other "strange" things and most probably will never return.
As a regular user you are not allowed to read/check a lot of files (belong to other users). Also there are a lot of binaries (like executables, libraries, database, compressed and encrypted files, ...) which may or may not contain the specified string and you may or may not catch that - depending on the searching algorithm.

So please specify your issue a bit better and also post what did you already try, which language do you prefer and other useful informations.
 
1 members found this post helpful.
Old 08-09-2018, 12:00 PM   #7
vysero
Member
 
Registered: May 2018
Posts: 137

Original Poster
Rep: Reputation: Disabled
To clarify, what I want to do is search through about 408.9 MB worth of .py, .txt, .cpp and .h files and maybe a few others for some keywords. I like the idea of the grep search. So lets say I have a script ImplementStatusController.h. What I want to do is search these directories for any .cpp scripts which are importing this ImplementStatusController.h script. If that doesn't work, then what I want to do is search these directories for keywords like "TipSelection" or what have you.
 
Old 08-09-2018, 12:02 PM   #8
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,081

Rep: Reputation: 4137Reputation: 4137Reputation: 4137Reputation: 4137Reputation: 4137Reputation: 4137Reputation: 4137Reputation: 4137Reputation: 4137Reputation: 4137Reputation: 4137
so construct a find command to collect the files you are looking for and pipe the result into an xargs grep.
 
Old 08-09-2018, 12:08 PM   #9
vysero
Member
 
Registered: May 2018
Posts: 137

Original Poster
Rep: Reputation: Disabled
So, grep -lr ImplementStatusController * solved my script problem. Now I am trying to figure out the string portion of the search because as I figured I coulnd't find the script I was looking for.
 
Old 08-09-2018, 12:20 PM   #10
vysero
Member
 
Registered: May 2018
Posts: 137

Original Poster
Rep: Reputation: Disabled
Wait, grep -lr string * works just fine lol I have a few files to start looking in now at least.
 
  


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
sed - Search and Replace /phrase Darrell22 Programming 4 03-05-2013 12:50 PM
how do i search the entire network for a printer baronobeefdip Debian 5 11-12-2011 11:06 PM
I can't think of how to phrase a search for this so bear with me (WiFi issues) dkippers Ubuntu 3 09-27-2009 11:46 PM
Which command to search text/phrase in file? b:z Linux - General 2 03-30-2005 09:11 PM
Search all man pages for a phrase suguru Linux - Software 1 09-12-2004 06:38 AM

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

All times are GMT -5. The time now is 01:19 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