Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am wondering is there a way to increase find speed in terminal, it doesn't make sense that using internet google to search will have a better speed than doing a local search for strings or just file names.

I am wondering is there a way to have a local indexing base, once built, in the future, the find command could be super fast.

Or any other suggestions?

Thanks!

share|improve this question
    
Can you edit your post with your operating system and/or distribution? –  JodieC Jun 13 '12 at 3:05
add comment

4 Answers

Try using locate, it should do what you want.

share|improve this answer
9  
Its usually a good idea to flesh out the answer a bit more. Like mentioning what package locate comes from (usually slocate), and to use updatedb for rebuilding the DB. :-) –  Patrick Jun 13 '12 at 0:43
add comment

It depends much on what your search criterion is.

If you search for filenames or filename patterns, locate is much faster, but not suitable for freshly generated files, since the index used is normally updated only once per day. But if you can use it, it is super fast.

But with find you can search for file size, file age and other things, which aren't searchable by locate.

If you know where to search, you can use the path to delimit the search scope:

find /some/path -size -10M -size +2M -mtime -365 ...

would only search files from 2 to 10 M, maximum 1 year old in /some/path.

Programs, available in the path can be searched by which, help, lib and configuration files with whereis. Examples:

which java
/usr/bin/java

whereis firefox 
firefox: /usr/bin/firefox /etc/firefox /usr/lib/firefox /usr/share/firefox /usr/share/man/man1/firefox.1.gz
share|improve this answer
add comment

As others have pointed out, locate may be a better tool for simpler searcher.

However, for more complex searches you're probably stuck with find.

One way to speed up find is to narrow down which directory your files are in instead of searching all of the root directory.

share|improve this answer
add comment

Use locate

The reason is that locate uses a database of all the existing directories and files that's already been built just like you imagined!
http://linux.about.com/od/commands/l/blcmdl5_locatedb.htm

At some set (and changeable) interval, a job runs does scans the file system and then builds a database with it. It is then this database (locatedb), with its appropriate indexes that the locate command goes against instead of scanning through your hard drive at that point.

So the upside is that it's very fast in comparison to a hard drive scan. The downside is that the locate database (locatedb) is not 'live' so can only be used for files that existed 'as of' the last scan.

To update locatedb now run updatedb (or sudo updatedb if necessary)

btw I just ran sudo updatedb locally and it took 3 1/2 seconds! I have 31,000 files.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.