2013-06-23 30 views

回答

8

man locate

If --regex is not specified, PATTERNs can contain globbing characters. If any 
PATTERN contains no globbing characters, locate behaves as if the pattern 
were \*PATTERN*. 

因此,當你發出

locate rhyth* 

locate不會找到它,因爲沒有符合這個模式沒有文件:因爲有一個水珠的性格,找到意志真的試圖匹配(在正則表達式):^rhyth.*並且顯然沒有這樣的匹配(在完整路徑上)。

在你的情況,你可以嘗試:

locate "/home/sh/.local/share/rhythmbox/rhyth*" 

locate '/rhyth' # equivalent to locate '*/rhyth*' 

但是,這不是很好的,是嗎?

現在,看看第一個選項中man locate

-b, --basename 
      Match only the base name against the specified patterns. This 
      is the opposite of --wholename. 

萬歲!行:

locate -b "rhyth*" 

應該工作,你希望它:定位與基名匹配(在正則表達式)的文件:^rhyth.*

希望這有助於。

編輯。爲了回答您的評論:如果你想locate文件夾中的所有/home/sh/music/ JPG 文件,這應該這樣做:

locate '/home/sh/music/*.jpg' 

(無-b這裏,它不會工作)。請注意,這將顯示文件夾/home/sh/music以及在其子文件夾中的所有jpg文件。你可能會傾向於使用-i標誌(忽略大小寫),讓你發現那些有大寫JPG擴展:

locate -i '/home/sh/music/*.jpg' 

編輯2。更好地說它在某處:locate命令與數據庫—一起工作,這就是爲什麼它可以比find快得多。如果你有最近的文件,他們不會是locate d,如果你刪除了一些文件,它們可能仍然是locate d。如果在這種情況下(這可能是你的其他意見的目的)的時候,你必須更新locate的數據庫:爲根,問題:

updatedb 

警告。命令updatedb可能需要幾分鐘才能完成,請不要擔心。

+0

我討厭設置一個更愚蠢的問題,但是可以指定某個位置嗎?例如我試圖做:找到-b「/home/sh/music/*.jpg」,但它似乎沒有工作 – Tebe

+0

@gekannt在這種情況下,你不需要'-b'標誌。 –

+0

好吧,我試過它不起作用,如果我找到了。 * .jpg,我得到很多文件,如果我找到了 - 什麼都沒有。 https://dl.dropboxusercontent.com/u/18776391/storage/21%3A22%3A1323062013_001.png https://dl.dropboxusercontent.com/u/18776391/storage/21%3A25%3A5723062013_001.png https://開頭dl.dropboxusercontent.com/u/18776391/storage/21%3A28%3A3423062013_001.png – Tebe