LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-07-2016, 04:46 PM   #1
Dafydd
Member
 
Registered: Oct 2008
Posts: 344

Rep: Reputation: 29
Need help finding a text file on my hard drives


I have lost a text file on my computer. I have the drive on my desktop, and 2 remote drives, which contain backups and archives. There is one word in the file that I have only used once. If I could find that word, I would have a path to the file.

How can I search for that word? I have read t he manual for 'find' but it is information overload for me.

Can someone help
 
Old 08-07-2016, 04:51 PM   #2
notKlaatu
Senior Member
 
Registered: Sep 2010
Location: Lawrence, New Zealand
Distribution: Slackware
Posts: 1,077

Rep: Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732
Code:
find /path/to/drive/or/dir/you/want/to/search -type f -exec grep -i theOneWordYouUsedOnlyOnce {} \;
You could further narrow the scope of your search if you know for sure that the text file is named ".txt" or something about its name, but I guess since the file is lost, it's best to throw a wider net.

Last edited by notKlaatu; 08-07-2016 at 04:52 PM.
 
1 members found this post helpful.
Old 08-07-2016, 07:35 PM   #3
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
Code:
grep -r 'word' /dira /dirb /dirc
It's probably not a binary file so you can use the -I flag to speed it up (by ignoring binary files)

This would probably be faster then the find / grep since the above will run grep for every single file it finds. unless you have more information about the file to filter - like its last modified time (more then / less then a week?), or maybe its size. If it's a text file, probably smaller then 512K

Last edited by Sefyir; 08-07-2016 at 07:37 PM.
 
Old 08-11-2016, 10:11 PM   #4
Dafydd
Member
 
Registered: Oct 2008
Posts: 344

Original Poster
Rep: Reputation: 29
Code:

find /path/to/drive/or/dir/you/want/to/search -type f -exec grep -i theOneWordYouUsedOnlyOnce {} \;

/Code:

This performed exactly as I wanted. If the word exist it got lost in the 50+ pages of hits. I swear I have only used the targeted word "dreamed" once since I got this new computer. Seems like all the message about 'dreamed of vacations'etc got tags.. I did not know my computer was saving all that juck.

Thanks for the feedback and help
Dave
 
Old 08-12-2016, 12:37 AM   #5
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,158

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Quote:
grep -rnw '/path/to/somewhere/' -e "pattern"
above code taken from this link: http://stackoverflow.com/questions/1...tring-on-linux

or try this command below it's a recursive search:

Quote:
find /home/folderName -name '*.txt' -print0 | xargs -0r grep -H 'secret_word'

Last edited by JJJCR; 08-12-2016 at 01:51 AM. Reason: edit
 
Old 08-12-2016, 12:47 AM   #6
timl
Member
 
Registered: Jan 2009
Location: Sydney, Australia
Distribution: Fedora,CentOS
Posts: 750

Rep: Reputation: 156Reputation: 156
I normally use

Quote:
find /path/to/drive/or/dir/you/want/to/search -type f -iname *theOneWordYouUsedOnlyOnce*
which zeroes in on what you want
 
Old 08-12-2016, 11:11 AM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
You need to get more specific about this file. How long ago was it modified? Would it be owned by your user or another user? How big/small is it? Are there any particular characters you know are in the file name, or do you know the file extension? All of these will help filter out the 50+ pages of trash. "dreamed" isn't exactly a unique word, there are plenty of system configuration files, browser cache files, etc. that can contain that word, so you need to get more specific about the file you're looking for to separate it from the pack.

Quote:
find /path/to/drive/or/dir/you/want/to/search -type f -iname *theOneWordYouUsedOnlyOnce*
That would only find files with 'theOneWordYouUsedOnlyOnce' in the name of the file, not in the contents.

notKlaatu's suggestion in post #2 is the right approach, now you just need to start adding more filters to the find to get rid of the junk. The iname, mtime, size, and user flags would probably be the most appropriate.

Last edited by suicidaleggroll; 08-12-2016 at 11:14 AM.
 
Old 08-12-2016, 05:46 PM   #8
Doug G
Member
 
Registered: Jul 2013
Posts: 749

Rep: Reputation: Disabled
grep -irl works for me
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
question regarding finding data from a text file j123 Linux - Newbie 8 03-23-2010 08:30 AM
Finding the Physical Hard Drives amirsd Linux - Newbie 1 12-04-2009 01:55 PM
Sun Ultra 10 not finding hard drives mwx Solaris / OpenSolaris 3 01-24-2009 05:40 AM
newbie:finding my windows hard drives jamil_1 Linux - Newbie 17 03-12-2007 06:45 PM
Finding Text in an html file Xaque208 Linux - Software 3 11-15-2004 10:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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