Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.