正如說明中所述。我首先檢查我們的數據庫是最新的定位命令在mac上的Documents文件夾內找不到任何內容
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
可以
人幫我?我一直堅持這個好半小時左右。
啊,所以這就是爲什麼,我會用自制的更新,我對mdfind不熟悉,因爲速度原因使用定位,運行mdfind似乎速度不快,但我不認爲你知道這是爲什麼? – 2013-04-08 20:47:01
'mdfind'使用Spotlight索引 - 一個類似於locate的預構建數據庫,除了它包含名稱之外的許多文件屬性,並且它不斷更新。有關更多信息,請參閱[關於SU的此博客文章](http://blog.superuser.com/2011/06/03/digging-deeper-mastering-spotlight-in-os-x/)。 – 2013-04-08 21:01:39
根據博客評論我鏈接'mdfind'使用Spotlight的索引,通常保持最新,所以你不需要手動重新索引。因此,我不打擾安裝自制軟件_only_替代'locate'實現,並堅持'mdfind'並添加別名('alias locate ='mdfind -name')。至於速度,因爲兩者都使用索引數據庫,它們應該同樣快 - 速度差異可能有很多不同的原因,從不同的數據庫大小,索引格式,排序算法到前端工具中的優化(或者_appearance_比另一個更快)。 – 2013-04-08 21:07:04