为什么 UNIX 定位命令仍然显示不再存在的文件/文件夹?

发布于 2024-07-25 14:04:07 字数 350 浏览 4 评论 0原文

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

问题是,我已经从“应用程序”文件夹中卸载了 MAMP,也卸载了首选项文件,但是当我在终端中运行“定位 MAMP”命令时,为什么它仍然显示我的所有 /Applications/MAMP/ 内容,就好像它们都还在那里一样? 当我“cd”进入 /Applications/MAMP/ 时,它不存在?

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

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.

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?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

硬不硬你别怂 2024-08-01 14:04:07

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


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

locate 数据库通常由用户 '' 构建没有人”和
locate.updatedb(8) 实用程序会跳过不可读的目录
对于用户“nobody”、组“nobody”或世界。 例如,如果您的
HOME 目录不是世界可读的,您的任何文件都不在数据库中。

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.


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:

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.

才能让你更想念 2024-08-01 14:04:07

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

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

现在我已经找到 mdfind。 它使用 Spotlight 文件索引,与 locatedb 相比,OSX 在保持最新方面要好得多。 它还具有更强大的功能,可以从命令行搜索内容。

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

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.

慕巷 2024-08-01 14:04:07

事实上,locate 命令会通过索引进行搜索,这就是它速度相当快的原因。
索引由 updatedb 命令生成,该命令通常作为每晚运行
或每周工作。

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

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.

So to update it manually, just run updatedb.

玉环 2024-08-01 14:04:07

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

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.

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.
凉城 2024-08-01 14:04:07

查看locate 手册页

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

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

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

Take a look at the locate man page

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文