Is there a search command on Unix command line to provide sorted relevant results within the files on the computer, similar to the way Google provides relevant results from the internet and Windows 7 provides search results from the computer?
-
I have this alias to locate files within the current directory and sub-directories. alias f='find . -name "*" | grep ' If I need to open file xyz.txt which is in /home/sapan/abc/def/mno/pqr/xyz.txt and my current working directory is /home/sapan, instead of traversing to pqr, I just hit the command > f xyz ./abc/def/mno/pqr/xyz.txt >subl ./abc/def/mno/pqr/xyz.txt and the file opens in sublime text. Similary I use the below alias for text search. alias ft='find . -name "*" | xargs grep ' There are obvious limitations to these approach, like at one point of time I can search only with one parameter and have to add a " | grep mno" after f xyz to locate the exact copy of the file if there is file xyz.txt in pqr. Also I have to manually copy and paste the desired file location. I haven't yet explored alias in zsh and will be exploring soon. I wonder if there is any service which makes searching file really easy like the way Google indexes searches as per relevance. Thanks to Dorin, locate does help do some of the magic and is extremely fast but I would like to use arrow buttons to move to the desired file and provide a command on that file like subl, cd, (something similar to vim - if you type vim folderName, a list opens up and you can select the file u want to open). Does something like this exist. All the above ideas exist in pieces but could not find anything on the internet. I had Microsoft Windows as a topic since Windows 7 search sometimes works similarly but is very slow. I know, Heights of Laziness :)
-
Answer:
Google uses a huge index of everything that's online. For that, you basically need twice the space on your hard-drive. No UNIX tool would require that of you. However, http://en.wikipedia.org/wiki/Grep searches through your files. Also it's instructive to search files by names by using http://linux.about.com/library/cmd/blcmdl1_slocate.htm. After your updates, I think it's better to recommend http://en.wikipedia.org/wiki/Strigi and http://userbase.kde.org/Nepomuk. I cannot say, however, that I know how they integrate in the normal UNIX environment.
Dorin LazÄr at Quora Visit the source
Other answers
Have you tried cscope yet? It is basically used to navigate in C/C++ coding projects, but I think it is what you want on a bigger scale. I have not tried it outside, C/C++ code but you can try it to know if it works for you.
Naveen Jain
This hasn't been mentioned so I'll mention this, the command is called "locate", it uses an index/DB as it's backend so you need to update that frequently (a cron job every night does fine) using updatedb. locate works from anywhere for all files. In typical unix fasion you have your regexp options and so forth. It doesn't search inside the file to the best of my knowledge though. Also reading your answer it looks like you're not really using file to fullest, nor are you using xargs or bash defined functions. I'll state a really simple case (You'll want to modify to your needs): search(){ vim $(locate $1 | head) } $ search unamepass If you're not concerned about using only CLI, you can use something like gnome's GUI search, just hit the Super key and type away. Then your arrows. Also if you're using something like sublime, emacs or vim anyway, they have their own plugins that let you search and open files from inside them. If you really want a user navigable indexed search for the terminal though, you're going to have to write that piece of TUI yourself.
Anhad Jai Singh
Its not crystal clear- what you mean by 'search' within the computer. I am assuming you mean searching the files in various folder levels - starting from the root. The command is - 'find' Please refer to the man page of the command for different variants and customizations, like which folder you want to search, the depth of search, whether it should be recursive or not, if its a folder you are looking for or a file. Link: http://unixhelp.ed.ac.uk/CGI/man-cgi?find Please note: The command works like the 'grep' command in Unix. You cannot do a fuzzy string match while using 'find'.
Rohit Kulkarni
Related Q & A:
- How to remove path of my command line?Best solution by Super User
- How to create jar file from command line?Best solution by Stack Overflow
- How can I send big music files from my computer to my friends by email?Best solution by Yahoo! Answers
- How to change brightness on Linux desktop through the command line?Best solution by Super User
- What is a good term for a search on Google?Best solution by wiki.answers.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.