2

I run updatedb like this: updatedb --localpaths="/a /b"

/a is a removable drive. /b is the local hard drive. Although /a's not always accessible to me, I frequently want to run locate to find if I have a certain file on it (based on the last time I ran updatedb).

The problem is, if I run updatedb when it's not plugged in, I get an error:

/usr/bin/find: '/a': No such file or directory

The database gets the latest information about /b, but it removes /a's existing data. Is there a way to keep /a's data when /a isn't plugged in during updatedb?

I think this might be possible with multiple databases, one for /a and another for /b. Then a script can check whether or not /a is plugged in when it decides whether or not to updatedb.

But the man page for both commands kind of assumes I know a lot more than I do (e.g., what FINDOPTIONS does), so I'm hoping there's an easier solution to this problem.

Daniel Kaplan
  • 757
  • 10
  • 25

1 Answers1

1

I don't know Linux on Windows, nor the GNU version of locate, but you should be able to do what you want. There is a longer version of the manual here.

Replace your single updatedb --localpaths="/a /b" by 2 commands,

updatedb --localpaths="/b"
if [ -d "/a" ]; then updatedb --localpaths="/a" --output=/dir/mydb; fi

where /dir/mydb is the full pathname of the file you want to hold the database in.

When you do a locate, set the environment variable LOCATE_PATH to /dir/mydb::. In principle :: should mean use the standard db.

If :: doesnt work, you may be able to get the filename of the standard db by running updatedb --help. It might say, for example, the default is /usr/local/var/locatedb. You can then set LOCATE_PATH=/dir/mydb:/usr/local/var/locatedb . You can also use the -d option to locate to provide this list of dbs.

meuh
  • 49,672
  • 2
  • 52
  • 114
  • `::` worked as advertised, FWIW. Thanks for the help – Daniel Kaplan Sep 22 '22 at 00:29
  • Oh yeah. I wanted to know if that longer version of the manual is accessible through a local command? I often end up asking questions here because I don't know how to find anything as thorough as your link. In fact, "Find utils" is the last place I'd think to look for information about `locate` and `updatedb`. How does one go from the man page of these commands to discovering your link without posting a question on stack overflow along the way? – Daniel Kaplan Sep 22 '22 at 00:33
  • 1
    Actually, the "find utils" page is a rare example of collected help on a subject. Sometimes, an http link is mentioned at the bottom of a man page, but probably not in this case. I don't remember how I found it initially, but I always keep short notes on commands when I use them for the first time, and the notes grow over time as snippets of info get discovered, often by reading answers on stackexchange. It's a slow process. – meuh Sep 22 '22 at 06:07