2017-11-18 2 views
0

나는 이미지의 목록을 다음 줄을 사용하여 수집을 포함 싶지 않다 :정규식 배쉬에서 : 디렉토리

# 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. 정규 표현식을 수백 가지 시도해 본 결과 가장 좋은 결과를 얻었습니다. 디렉토리 트리없이 파일 이름을 출력하거나 정규 표현식에 따라 파일 이름을 출력하는 방법이 있습니까? -printf 옵션이 다음 대신 -execdir echo {} \;을 사용할 수 있습니다 (맥 OS X의 최신 버전에서와 같이) find의 구현에 사용할 수없는 경우

감사

+0

아, 죄송합니다, 리눅스 – Eugeen

답변

2

이 (

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

해야한다 그게 가능하다면) :

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