Locate 命令在 Mac 上的 Documents 文件夹中找不到任何内容

问题描述 投票:0回答:3

正如描述中所说。我首先检查我们的数据库是否是最新的

bin $ sudo /usr/libexec/locate.updatedb
Password:       #password entered and function executed without errors

然后我尝试在我的文档文件夹中搜索某些内容

bin $ cd ~/Documents/
Documents $ ls
    Mamp_workspace/                         Scenarios.docx                          gc01/
Documents $ locate Scenarios.docx   #nothing returned

然后我尝试另一个随机文件夹:

Documents $ cd ..
~ $ 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
~ $ locate website-terminal-copy-paste 
/Users/crashandburn4/website-terminal-copy-paste #correct result returned

有人可以帮助我吗?我已经被困在这个问题上大约半个小时了。

bash macos document locate
3个回答
17
投票

正如 plundra 所指出的,这是因为

locate
OSX 附带的旧且有缺陷,并且不会索引和/或报告
nobody
无法读取的文件,即使以 root 身份运行也是如此。不过,您可以做的是安装 homebrew,然后安装
GNU locate
,或者按照建议 here 使用
mdfind -name
代替(我手头没有 OSX 盒子来测试这一点)。


9
投票

这是因为您的文档文件夹不是世界可读的,这是一件好事,特别是在共享系统上。

locate(1) 手册页的 BUGS 部分对此进行了解释:

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

尝试运行

ls -ld ~/Documents

,您将看到权限。如果您不熟悉,维基百科上有一篇关于 
Unix 权限 的文章。


1
投票
您可以执行 sudo ln -s /usr/libexec/locate.updatedb /usr/local/bin/updatedb 以使 Updatedb 命令可用

© www.soinside.com 2019 - 2024. All rights reserved.