为什么unix locate命令仍然显示不再存在的文件/文件夹?

时间:2021-12-12 10:00:40

I recently moved my whole local web development area over to using MacPorts stuff, rather than using MAMP on my Mac. I've been getting into Python/Django and didn't really need MAMP any more.

我最近将整个本地Web开发区域移到了使用MacPorts的东西上,而不是在我的Mac上使用MAMP。我已经进入Python / Django并且不再需要MAMP了。

Thing is, I have uninstalled MAMP from the Applications folder, with the preferences file too, but how come when I run the 'locate MAMP' command in the Terminal it still shows all my /Applications/MAMP/ stuff as if it's all still there? And when I 'cd' into /Applications/MAMP/ it doesn't exist?

事实上,我已经从Applications文件夹中卸载了MAMP,也有偏好文件,但是当我在终端中运行'locate MAMP'命令时它仍然显示我的所有/ Applications / MAMP /东西,好像它仍然存在?当我'进入/ Applications / MAMP /它不存在?

Something to do with locate being a kind of index searching system, hence things these old filepaths are cached? Please explain why, and how to sort it so they don't show anymore.

与locate是一种索引搜索系统有关,因此这些旧的文件路径被缓存了吗?请解释原因,以及如何排序,以便它们不再显示。

5 个解决方案

#1


You've got the right idea: locate uses a database called 'locatedb'. It's normally updated by system cron jobs (not sure which on OS X); you can force an update with the updatedb command. See http://linux-sxs.org/utilities/updatedb.html among others.

你有正确的想法:locate使用一个名为'locateb'的数据库。它通常由系统cron作业更新(不确定OS X上的哪个);您可以使用updatedb命令强制更新。请参阅http://linux-sxs.org/utilities/updatedb.html等。


Also, if you don't find files which you expect to, note this important caveat from the BUGS section of OSX' locate(1) man-page:

此外,如果您没有找到您期望的文件,请注意OSX的locate(1)man-page的BUGS部分中的这一重要警告:

The locate database is typically built by user ''nobody'' and the locate.updatedb(8) utility skips directories which are not readable for user ''nobody'', group ''nobody'', or world. For example, if your HOME directory is not world-readable, none of your files are in the database.

定位数据库通常由用户“无人”构建,并且locate.updatedb(8)实用程序会跳过用户“无人”,组“无人”或世界无法读取的目录。例如,如果您的HOME目录不是世界可读的,则您的所有文件都不在数据库中。

#2


The other answers are correct about needing to update the locate database. I've got this alias to update my locate DB:

其他答案对于需要更新locate数据库是正确的。我有这个别名来更新我的定位数据库:

alias update_locate='sudo /usr/libexec/locate.updatedb'

I actually don't use locate all that much anymore now that I've found mdfind. It uses the spotlight file index which OSX is much better at keeping up to date compared to the locatedb. It also has quite a bit more power in what it can search from the command line.

我找到mdfind后,实际上我不再使用定位了。它使用聚光灯文件索引,与locateb相比,OSX更好地保持最新状态。它在从命令行搜索的功能方面也有相当多的功能。

#3


Indeed the locate command searches through an index, that's why it's pretty fast. The index is generated by the updatedb command, which is usually run as a nightly or weekly job.

实际上,locate命令搜索索引,这就是为什么它非常快。索引由updatedb命令生成,该命令通常作为夜间或每周作业运行。

So to update it manually, just run updatedb.

因此,要手动更新它,只需运行updatedb。

#4


According to the man page, its database is updated once a week:

根据手册页,其数据库每周更新一次:

NAME
     locate.updatedb -- update locate database

SYNOPSIS
     /usr/libexec/locate.updatedb

DESCRIPTION
     The locate.updatedb utility updates the database used by locate(1).  It is typically run once a week by
     the /etc/periodic/weekly/310.locate script.

#5


Take a look at the locate man page

看一下locate手册页

http://unixhelp.ed.ac.uk/CGI/man-cgi?locate+1

You'll see that locate searches a database, not your actual filesystem. You can update that database by using the updatedb command.

您将看到locate搜索数据库,而不是您的实际文件系统。您可以使用updatedb命令更新该数据库。

Also, since it's a database, unless you do update it regularly, locate wouln't find files that are in your filesystem that arn't in the database.

此外,由于它是一个数据库,除非您定期更新它,否则找不到文件系统中不在数据库中的文件。

#1


You've got the right idea: locate uses a database called 'locatedb'. It's normally updated by system cron jobs (not sure which on OS X); you can force an update with the updatedb command. See http://linux-sxs.org/utilities/updatedb.html among others.

你有正确的想法:locate使用一个名为'locateb'的数据库。它通常由系统cron作业更新(不确定OS X上的哪个);您可以使用updatedb命令强制更新。请参阅http://linux-sxs.org/utilities/updatedb.html等。


Also, if you don't find files which you expect to, note this important caveat from the BUGS section of OSX' locate(1) man-page:

此外,如果您没有找到您期望的文件,请注意OSX的locate(1)man-page的BUGS部分中的这一重要警告:

The locate database is typically built by user ''nobody'' and the locate.updatedb(8) utility skips directories which are not readable for user ''nobody'', group ''nobody'', or world. For example, if your HOME directory is not world-readable, none of your files are in the database.

定位数据库通常由用户“无人”构建,并且locate.updatedb(8)实用程序会跳过用户“无人”,组“无人”或世界无法读取的目录。例如,如果您的HOME目录不是世界可读的,则您的所有文件都不在数据库中。

#2


The other answers are correct about needing to update the locate database. I've got this alias to update my locate DB:

其他答案对于需要更新locate数据库是正确的。我有这个别名来更新我的定位数据库:

alias update_locate='sudo /usr/libexec/locate.updatedb'

I actually don't use locate all that much anymore now that I've found mdfind. It uses the spotlight file index which OSX is much better at keeping up to date compared to the locatedb. It also has quite a bit more power in what it can search from the command line.

我找到mdfind后,实际上我不再使用定位了。它使用聚光灯文件索引,与locateb相比,OSX更好地保持最新状态。它在从命令行搜索的功能方面也有相当多的功能。

#3


Indeed the locate command searches through an index, that's why it's pretty fast. The index is generated by the updatedb command, which is usually run as a nightly or weekly job.

实际上,locate命令搜索索引,这就是为什么它非常快。索引由updatedb命令生成,该命令通常作为夜间或每周作业运行。

So to update it manually, just run updatedb.

因此,要手动更新它,只需运行updatedb。

#4


According to the man page, its database is updated once a week:

根据手册页,其数据库每周更新一次:

NAME
     locate.updatedb -- update locate database

SYNOPSIS
     /usr/libexec/locate.updatedb

DESCRIPTION
     The locate.updatedb utility updates the database used by locate(1).  It is typically run once a week by
     the /etc/periodic/weekly/310.locate script.

#5


Take a look at the locate man page

看一下locate手册页

http://unixhelp.ed.ac.uk/CGI/man-cgi?locate+1

You'll see that locate searches a database, not your actual filesystem. You can update that database by using the updatedb command.

您将看到locate搜索数据库,而不是您的实际文件系统。您可以使用updatedb命令更新该数据库。

Also, since it's a database, unless you do update it regularly, locate wouln't find files that are in your filesystem that arn't in the database.

此外,由于它是一个数据库,除非您定期更新它,否则找不到文件系统中不在数据库中的文件。