为什么 UNIX 定位命令仍然显示不再存在的文件/文件夹?
我最近将我的整个本地 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您的想法是正确的:
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 theupdatedb
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.
关于需要更新定位数据库的其他答案是正确的。 我有这个别名来更新我的定位数据库:
现在我已经找到 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:
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.
事实上,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.
根据手册页,其数据库每周更新一次:
According to the man page, its database is updated once a week:
查看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.