Macos 定位命令can';在mac上的Documents文件夹中找不到任何内容
正如描述中所说。我首先检查我们的数据库是最新的Macos 定位命令can';在mac上的Documents文件夹中找不到任何内容,macos,bash,documents,locate,Macos,Bash,Documents,Locate,正如描述中所说。我首先检查我们的数据库是最新的 mh547:bin crashandburn4$ sudo /usr/libexec/locate.updatedb Password: #password entered and function executed without errors 然后我尝试在我的文档文件夹中搜索一些内容 mh547:bin crashandburn4$ cd ~/Documents/ mh547:Documents crashandburn4$ ls
mh547:bin crashandburn4$ sudo /usr/libexec/locate.updatedb
Password: #password entered and function executed without errors
然后我尝试在我的文档文件夹中搜索一些内容
mh547:bin crashandburn4$ cd ~/Documents/
mh547:Documents crashandburn4$ ls
Mamp_workspace/ Scenarios.docx gc01/
mh547:Documents crashandburn4$ locate Scenarios.docx #nothing returned
然后我尝试另一个随机文件夹:
mh547:Documents crashandburn4$ cd ..
mh547:~ crashandburn4$ ls
Applications/ Movies/ drawable/ untitled-2.pdf
Desktop/ Music/ drawable-xhdpi/ untitled-2.synctex.gz
Documents/ Pictures/ dwhelper/ untitled-2.tex
Downloads/ Public/ linux_ssh* website-terminal-copy-paste
Dropbox/ Samsung/ scripts/ workspace/
Google Drive/ Sites/ untitled-2.aux workspace_copy_to_linux*
Library/ android-sdks/ untitled-2.log
mh547:~ crashandburn4$ locate website-terminal-copy-paste
/Users/crashandburn4/website-terminal-copy-paste #correct result returned
有人能帮我吗?我已经在这上面呆了半个多小时了。这是因为你的文档文件夹不是世界可读的,这是一件好事,特别是在共享系统上 手册页的BUGS部分对此进行了解释: 定位数据库通常由用户“nobody”和 updatedb(8)实用程序跳过不可读的目录 对于用户“nobody”、组“nobody”或世界。例如,如果您的 主目录不是世界可读的,您的任何文件都不在 数据库
尝试运行
ls-ld~/Documents
,您将看到权限。Wikipedia上有一篇关于你是否不熟悉这些的文章。正如plundra所指出的,这是因为OSX附带的locate
OSX是旧的、残废的,即使以root用户身份运行,也不会索引和/或报告任何人都无法读取的文件。不过,您可以做的是安装然后GNU locate
,或者按照建议使用mdfind-name
(我手边没有OSX框来测试这一点)。您可以使用sudo ln-s/usr/libexec/locate.updatedb/usr/local/bin/updatedb使updatedb命令可用啊,这就是为什么,我将用自制更新,我不熟悉mdfind,我使用locate是为了提高速度,在运行mdfind之后,它看起来也一样快,如果不是更快的话,我想你不知道为什么会这样?mdfind
使用Spotlight索引,这是一个预建的数据库,类似于locate,只是它除了名称之外还包含许多文件属性,并且不断更新。有关更多信息,请参阅。根据我链接的博客评论,mdfind
使用Spotlight的索引,该索引通常是最新的,因此您无需手动重新编制索引。因此,我不会为了替代的locate
实现而安装homebrew,而是坚持使用mdfind
并添加别名(alias locate='mdfind-name'
)。至于速度,由于两者都使用索引数据库,它们应该同样快——速度的差异可能有很多不同的原因,从不同的数据库大小、索引格式、排序算法到前端工具中的优化(或者看起来一个比另一个快)。非常棒,谢谢,非常有用。对于任何其他人的参考,您可以使用macports或homebrew轻松更新,软件包名称为findutils,并且(至少对我来说)虽然它现在可以搜索Documents文件夹,但我仍然建议在速度和效率方面使用如上所述的mdfind(我正在搜索的一个子文件夹仍然无法用locate定位)。虽然这是事实,但我认为如果您想在mac上使用locate,使用alias locate='mdfind-name'
更有用,因为内置的mdfind工作得很好,并且没有理由保留两个元数据数据库。