Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Make the locate command ignore certain directories' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Make the locate command ignore certain directories
Authored by: klktrk on Nov 14, '03 01:45:32PM

Following your hint gives me this error output when I try to run the revised script:

find: : unknown expression primary
csh: !: Command not found.




[ Reply to This | # ]
Make the locate command ignore certain directories
Authored by: klktrk on Nov 14, '03 01:55:53PM

Here's my code, by the way:

find ${SRCHPATHS} \( -regex "/Volumes" -o -regex "/Previous Systems" -o \
! -fstype local -o -fstype fdesc -o -fstype devfs \) -a \
-prune -o -print | \
tr '/' '\001' | \
(sort -T "$TMPDIR" -f; echo $status > $errs) | tr '\001' '/' > $filelist



[ Reply to This | # ]
Make the locate command ignore certain directories
Authored by: klktrk on Nov 14, '03 02:06:10PM

You know what's weird about the code is that you don't have a ! (not) operator in front of your regexs. Aren't you saying YES then to including /Volumes and /Previous Systems?



[ Reply to This | # ]
Make the locate command ignore certain directories
Authored by: ryo on Nov 14, '03 02:19:19PM

hmm, try escaping the "!" so it reads "\! fstype local" this may be a csh vs. tcsh thing?

also, the way the logic goes in the find arguments is find will only print the results that don't match all the other arguments. The 'and' binds tighter than the last 'or'.

In other words, if a file matches the dirs you added to the statement, then find will -prune it (not descend into the directory and waste time) and won't print the result. The same goes if any of the other args in the parentheses evaluate to true: they'll be '-prune'ed and then ignored.



[ Reply to This | # ]
Very bad hint
Authored by: Novajo on Nov 14, '03 03:56:21PM

Modifying system files is never a good idea, especially since there is an option to be passed at the command line to skip certain directories: it is --prune-path, as in:

/usr/libexec/locate.updatedb --prune-path="/Volumes /Previous\ System/"

See man locate.updatedb



[ Reply to This | # ]
doh!
Authored by: ryo on Nov 14, '03 04:43:05PM

I stand corrected: Use the method Navajo mentions.

In my defense, in figuring out how to exclude these directories I tried 'man locate' which told me nothing about excluding directories and nothing about creating a configuration file for locate.updatedb (/etc/locate.rc), and 'locate locate' to find any files associated with 'locate' and since there's no /etc/locate.rc on my machine I found no mention anywhere of an alternate way of controlling locate.updatedb. Nothing is even mentioned in the source of locate.updatedb.



[ Reply to This | # ]
Very bad hint
Authored by: klktrk on Nov 14, '03 06:29:36PM

Okay, so you don't think we should modify system files.... Then how do we pass the parameters you suggest? For example, the locate.updatedb command is run by the periodic weekly script. If we want to change which directories are parsed, then we would have to modify THAT system file.

Is it our system, or Apple's? I thought the whole point of UNIX was that you could make it do anything you want.

Or are you going to tell me I'm not "allowed" to rebuild my kernel, or build my own version of different utilities if I feel like it?



[ Reply to This | # ]
Very bad hint
Authored by: gmackenz on Nov 14, '03 06:54:04PM

Modifying a cron job is much safer than modifying system files or doing crazy things like I did once, where I compiled my own version of tcsh on my work solaris server once and set it up to use that spanky-fine tcsh as the default shell for all users (including root). Clever me, no?

A year later I upgraded the Solaris OS and the compiled tcsh was either removed accidently or was incompatible. Needless to say I could no longer log in remotely or locally after a system reboot. It took me and the system adminstrators a day or so to figure out what a bad boy I had been :(

MORAL:

Make changes to your local environmentals and don't monkey with system files/settings!



[ Reply to This | # ]
Very bad hint
Authored by: bluehz on Nov 14, '03 08:48:39PM

Does anyone else ever see the "The locate db is over 8 days old" msg when using locate. I like to use locate - but it seems the db is not being updated. I leave my machine on 24/7 so I know the crontasks are running - but it always says "over 8 days old"



[ Reply to This | # ]
Very bad hint
Authored by: cilly on Nov 15, '03 07:23:45AM

I guess you did an upgrade install? :-)

---
cilly



[ Reply to This | # ]
Very bad hint
Authored by: Novajo on Nov 16, '03 12:08:13AM

Sure it's your system and you do what you want. If you want to modify scripts, it is your right to do so. I just wouldn't do it if not necessary. And there is a significant difference between modifying system configuration files in /etc versus scripts in /usr/bin and others. For instance, there are hooks to do daily and weekly jobs that are already provided: create daily.local or weekly.local to add you own stuff to the cron job.

That said, the man page is out of sync and the suggestion I made actually does not work as mentionned elsehwere on this page, which blows because an up-to-date locate script is very powerful.

So go nuts: modify locate.updatedb. Personnally, I would instead get a newer version and install in /usr/local/.



[ Reply to This | # ]
Re: Very bad hint
Authored by: flunkedflank on Nov 15, '03 01:46:22AM

I see --prunepaths in the man page, but are you sure that it actually works? Looking at the source for locate.updatedb, I don't see it processing any command line arguments. I think the man page must be out of sync for some reason. (I'm using Panther.)



[ Reply to This | # ]
Make the locate command ignore certain directories
Authored by: klktrk on Nov 14, '03 02:18:21PM

Okay, so the code has to look like this ( The \! has to go before the parentheses).

Like so:

find ${SRCHPATHS} \! \( -path '/Volumes*' -o -path '/Previous Systems*' \
-o -fstype local -o -fstype fdesc -o -fstype devfs \) -a \
-prune -o -print | \
tr '/' '\001' | \
(sort -T "$TMPDIR" -f; echo $status > $errs) | tr '\001' '/' > $filelist



This seems to be working.



[ Reply to This | # ]