How to use locate in cygwin?

14

2

I'm trying to use locate to find files, but I'm not getting anything back from the program. It can't even find files that are in the current directory. How do I make locate work?

Phenom

Posted 2009-11-22T00:20:22.767

Reputation: 6 119

use sudo updatedb ? – ukanth – 2009-11-23T12:50:17.407

Answers

15

In essence, you have to run updatedb first, as this builds the database that locate uses.
Simply do updatedb --localpaths=c:/ as a first shot solution.

See this blog post for a bunch of good tips , including how to setup up updatedb via cygwin cron: https://web.archive.org/web/20061114000822/www.weiqigao.com/blog/2006/08/14/ten_steps_to_higher_cygwin_productivity.html (updated link to archive.org)

Google 'cygwin updatedb' for a relevant post if you are having trouble with paths that include spaces. I am not getting any trouble (other than permission denied) on WinXP Pro, but other platforms may require this.

dirkjot

Posted 2009-11-22T00:20:22.767

Reputation: 455

I've found that a simple invocation of updatedb won't work in Cygwin, as the default options (or --localpaths=c:/) will lead it into following links into infinite loops. I think this is because certain types of Windows 7 links don't appear as symbolic links to Cygwin, so it can't skip them (as the default -follow behavior is, counter-intuitively, supposed to) – Phil Goetz – 2017-11-14T15:35:04.417

The blogpost is unreachable.It would be better to inline its advice here. – reinierpost – 2019-09-13T10:05:32.370

1Thanks @reinierpost, fixed the link. The post is too long to inline, IMHO. – dirkjot – 2019-09-19T05:49:15.627

5

The blogpost has a new address, http://webpages.charter.net/weiqigao/2006/08/14/ten_steps_to_higher_cygwin_productivity.html

– Stefan Rasmusson – 2013-09-16T13:07:13.443

5

To use locate you need to run updatedb first.

Mark Byers

Posted 2009-11-22T00:20:22.767

Reputation: 576

-1

I think the command you want is find

Do man find to see the syntax and options

The locate command runs against a pre-built database of filenames

Ex Umbris

Posted 2009-11-22T00:20:22.767

Reputation: 928

1Find will at least do the job that is being requested if locate is not present or for what-ever reason not functioning. More slowly, as it won't have the pre-prepared data to search, but it will work and the results are more likely to be properly uptodate and complete (updatedb may have been configured to exclude some parts of the filesystem). – David Spillett – 2010-04-22T13:06:18.343

Yes, locate runs against a pre-built database. Why does that mean the OP wants find instead? – CarlF – 2009-11-23T15:01:13.250