2014-09-28 36 views
0

我有一個包含大量文件夾和子文件夾的硬盤。 格式是這樣的:以遞歸方式列出最後一個文件夾

/genre1 /藝術家/套的.jpg

的pictures1 /列表的,但它也可以是

/genre2 /套的.jpg

的pictures2 /名單

我想獲得.jpg所在路徑的完整列表。它們是每個文件夾樹的最後一個文件夾。

我該如何做一個shell腳本? 我試圖用mindepth或maxdepth和-type d來使用「find」,但是我不知道我必須尋找多少深度級別..它可以改變。

感謝

回答

0

如果你不使用gnu find您可以使用-links測試中this answer

find/-type d -links 2 -exec \ 
    find {} -maxdepth 1 -type f -name '*.jpg' -printf "%h\n" -quit \ 
\; 

,你可以這樣做

find/-type d -links 2 -exec \ 
    bash -c 'shopt -s dotglob nullglob; a=(*.jpg); ((${#a[@]}>0)) && echo "$1"' bash {} \ 
\; 
相關問題