定位命令在mac上的Documents文件夹中找不到任何内容

Mik*_*H-R 6 macos bash documents locate

正如它在描述中所说的那样.我首先检查我们的数据库是最新的

mh547:bin crashandburn4$ sudo /usr/libexec/locate.updatedb
Password:       #password entered and function executed without errors
Run Code Online (Sandbox Code Playgroud)

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

mh547:bin crashandburn4$ cd ~/Documents/
mh547:Documents crashandburn4$ ls
    Mamp_workspace/                         Scenarios.docx                          gc01/
mh547:Documents crashandburn4$ locate Scenarios.docx    #nothing returned
Run Code Online (Sandbox Code Playgroud)

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

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
Run Code Online (Sandbox Code Playgroud)

谁能帮我?我已经坚持了半个小时左右.

Adr*_*rth 15

正如plundra所指出的那样,这是因为locateOSX附带的旧版本已经过时并且已经瘫痪,并且不会索引和/或报告nobody即使以root身份运行也无法读取的文件.你可以做的是安装自制软件然后GNU locate,或者,正如这里所建议的那样使用mdfind -name(我手边没有OSX盒来测试).

  • `mdfind`使用Spotlight索引 - 一个类似于locate的预建数据库,除了它包含除名称之外的许多文件属性,并且它不断更新.有关详细信息,请参阅[此SU上的博客文章](http://blog.superuser.com/2011/06/03/digging-deeper-mastering-spotlight-in-os-x/). (2认同)
  • 根据博客评论我链接的`mdfind`使用Spotlight的索引,该索引通常保持最新,因此您无需手动重新索引.因此,我不打算安装自制的_only_替代`locate`实现并坚持使用`mdfind`并添加一个别名(`alias locate ='mdfind -name'`).至于速度,因为两者都使用索引数据库,它们应该同样快 - 速度差异可能有很多不同的原因,从不同的数据库大小,索引格式,排序算法到前端工具中的优化(或者_appearance_那个是比其他更快). (2认同)

plu*_*dra 8

这是因为您的Documents-folder不是世界可读的,这是一件好事,特别是在共享系统上.

locate(1)手册页的BUGS部分解释了它:

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

尝试运行ls -ld ~/Documents,您将看到权限.如果你不熟悉这些,维基百科有一篇关于Unix权限的文章.