2017-11-18 149 views
0

我有圖像的列表,使用下面的行收集:正則表達式中的Bash:不想include目錄

# find . -mindepth 1 -type f -name "*.JPG" | grep "MG_[0-9][0-9][0-9][0-9].JPG" 

輸出:

./DCIM/103canon/IMG_0039.JPG 
./DCIM/103canon/IMG_0097.JPG 
./DCIM/103canon/IMG_1600.JPG 
./DCIM/103canon/IMG_2317.JPG 
./DCIM/IMG_0042.JPG 
./DCIM/IMG_1152.JPG 
./DCIM/IMG_1810.JPG 
./DCIM/IMG_2564.JPG 
./images/IMG_0058.JPG 
./images/IMG_0079.JPG 
./images/IMG_1233.JPG 
./images/IMG_1959.JPG 
./images/IMG_2012/favs/IMG_0039.JPG 
./images/IMG_2012/favs/IMG_1060.JPG 
./images/IMG_2012/favs/IMG_1729.JPG 
./images/IMG_2012/favs/IMG_2013.JPG 
./images/IMG_2012/favs/IMG_2317.JPG 
./images/IMG_2012/IMG_0079.JPG 
./images/IMG_2012/IMG_1403.JPG 
./images/IMG_2012/IMG_2102.JPG 
./images/IMG_2013/IMG_0060.JPG 
./images/IMG_2013/IMG_1311.JPG 
./images/IMG_2013/IMG_1729.JPG 
./images/IMG_2013/IMG_2013.JPG 
./IMG_0085.JPG 
./IMG_1597.JPG 
./IMG_2288.JPG 

但我只希望最後部分, IMG_ \ d \ d \ d \ d.JPG。我已經嘗試了數百個正則表達式,這是給我最好的結果。有沒有一種方法可以打印出文件名,而不是在目錄樹之前,還是僅僅是正則表達式?

感謝

+0

ah對不起,linux – Eugeen

回答

2

應該

find . -mindepth 1 -type f -name "*MG_[0-9][0-9][0-9][0-9].JPG" -printf "%f\n" 
0

如果-printf選項不可用你的實現find(如在Mac OS X的最新版本), 那麼你可以使用-execdir echo {} \;代替(如果可以的話):

find . -mindepth 1 -type f -name "*MG_[0-9][0-9][0-9][0-9].JPG" -execdir echo {} \; 
+0

不是'-execdir'仍然以'。/'爲基礎名前綴? – melpomene

+0

@melpomene在我的find版本中找不到(Mac OS X) – janos