faster file search script, at least I hope so :)

Today it occured to me that, instead everytime running find command to find files, I could cache find results somewhere, then look into it with grep. Here is how its gone:

find.sh ( -rwxr----- root:users )-> in /etc/cron.hourly


#!/bin/bash
find / > /home/yasar/findlog.txt 2> /dev/null

findlog.txt ( -rw-r----- )-> in my home folder, generated automatically by find.sh

and finally,

bul= find in my language :)] (-rwxr----- yasar:users) → in ~/myscripts → added to the path from ./bashrc file


#!/bin/bash
grep $1 /home/yasar/findlog.txt

This seems to be working for now, I was wondering if I am doing anything wrong. What do you think about this?

Why not just use the findutils-locate package which does this in an organised way.

yasar11732 wrote:
> This seems to be working for now, I was wondering if I am doing
> anything wrong. What do you think about this?

give ‘locate’ a try


DenverD
CAVEAT: http://is.gd/bpoMD [posted via NNTP w/openSUSE 10.3]

I didn’t know either of them before, checking man pages now :slight_smile:

Edit: I guess both are the same thing, right?

yasar11732 wrote:
> Edit: I guess both are the same thing, right?

yes…sorry, i didn’t see that Ken had already put you on it…

it is really kinda simple to use, just install it and it auto-sets up
a cron to run a daily peek around and updates a db…

you can kick off the initial look around…man locate tells how…once
the db is ready you get answers almost instantaneously…


DenverD
CAVEAT: http://is.gd/bpoMD [posted via NNTP w/openSUSE 10.3]

However, notice that ‘locate’ will show files that were present during the last update of the locate-database only (every 24 hours by default).

As far as I remember (not sure though) ‘locate’ is not set up and activated right after the install. One should run

updatedb

as root first. The very first setup will take quite a lot of cpu-resources (and time, depending on how many files you have), but the updates will only need very little (at least I never really noticed an ‘updatedb’ running).