2013-04-08 438 views
6

正如說明中所述。我首先檢查我們的數據庫是最新的定位命令在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 
可以

人幫我?我一直堅持這個好半小時左右。

回答

12

正如plundra指出的那樣,這是因爲OSX附帶的locate已老化並且沒有索引和/或報告nobody無法讀取的文件,即使以root身份運行也是如此。你可以做什麼雖然是安裝homebrew然後GNU locate,或者,建議here使用mdfind -name而不是(我沒有一個OSX框在手來測試這個)。

+0

啊,所以這就是爲什麼,我會用自制的更新,我對mdfind不熟悉,因爲速度原因使用定位,運行mdfind似乎速度不快,但我不認爲你知道這是爲什麼? – 2013-04-08 20:47:01

+1

'mdfind'使用Spotlight索引 - 一個類似於locate的預構建數據庫,除了它包含名稱之外的許多文件屬性,並且它不斷更新。有關更多信息,請參閱[關於SU的此博客文章](http://blog.superuser.com/2011/06/03/digging-deeper-mastering-spotlight-in-os-x/)。 – 2013-04-08 21:01:39

+1

根據博客評論我鏈接'mdfind'使用Spotlight的索引,通常保持最新,所以你不需要手動重新索引。因此,我不打擾安裝自制軟件_only_替代'locate'實現,並堅持'mdfind'並添加別名('alias locate ='mdfind -name')。至於速度,因爲兩者都使用索引數據庫,它們應該同樣快 - 速度差異可能有很多不同的原因,從不同的數據庫大小,索引格式,排序算法到前端工具中的優化(或者_appearance_比另一個更快)。 – 2013-04-08 21:07:04

7

這是因爲您的Documents-folder不是世界可讀的,這是一件好事,特別是在共享系統上。

locate(1)手冊頁的BUGS部分解釋它:

數據庫通常由用戶建立「」沒人'和 locate.updatedb的定位(8)工具跳過目錄哪些不是對於用戶'nobody'',組''nobody''或世界而言可讀的 。例如,如果您的HOME目錄不是全球可讀的,則您的文件都不在 數據庫中。

嘗試運行ls -ld ~/Documents,您將看到權限。如果您對這些不熟悉,維基百科有關於Unix permissions的文章。

1

你可以做須藤LN -s /usr/libexec/locate.updatedb在/ usr/local/bin目錄/ updatedb的使updatedb的命令可用

+1

雖然這是真的,但我認爲使用'alias locate ='mdfind -name''是更有用的,因爲內置的mdfind運行良好,並且沒有理由保留兩個元數據庫。 – 2016-11-09 15:41:22

相關問題