I will like to use "find" and locate" to search for source files in my project, but they take a long time to run. Are there faster alternatives to these programs I don't know about, or ways to speed up the performance of these programs?
Searching for source files in a projectUse a simpler command Generally, source for a project is likely to be in one place, perhaps in a few subdirectories nested no more than two or three deep, so you can use a (possibly) faster command such as
Make use of project metadata In a C project you'd typically have a Makefile. In other projects you may have something similar. These can be a fast way to extract a list of files (and their locations) write a script that makes use of this information to locate files. I have a "sources" script so that I can write commands like Speeding up findSearch fewer places, instead of Speeding up locateEnsure it is indexing the locations you are interested in. Read the man page and make use of whatever options are appropriate to your task.
Remove the need for searchingMaybe you are searching because you have forgotten where something is or were not told. In the former case, write notes (documentation), in the latter, ask? Conventions, standards and consistency can help a lot. |
||||
|
|
|
I used the "speeding up locate" part of RedGrittyBrick's answer. I created a smaller db:
then pointed |
||||
|
|
locateshould already be plenty fast, considering that it uses a pre-built index (the primary caveat being that it needs to be kept up to date), whilefindhas to read the directory listings. – afrazier Sep 29 '11 at 13:22find /usr/src -name fprintf.con my OpenBSD desktop machine, it returns the locations of those source files in less than 10 seconds.locate fprintf.c | grep '^/usr/src.*/fprintf.c$'comes back in under a second. What is your definition of "long time to run" and how do you usefindandlocate? – Kusalananda Sep 29 '11 at 14:15