개발관련/Linux

linux find에서 디렉토리를 제외하는 방법

Rateye 2021. 8. 6. 10:39
728x90
반응형

 

질문 : find에서 디렉토리를 제외하는 방법. 명령

find 명령을 실행하려고하는데 특정 디렉토리를 제외하려면 어떻게해야합니까?

다음은 우리가 사용 find

for file in $(find . -name '*.js')
do 
  java -jar config/yuicompressor-2.4.2.jar --type js $file -o $file
  done
  
답변

-prune 스위치를 사용하십시오. 예를 들어, misc 디렉토리를 제외하려면 find 명령에 -path ./misc -prune -o

find . -path ./misc -prune -false -o -name '*.txt'
  

다음은 여러 디렉토리가있는 예입니다.

find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -false -o -name '*.txt'
  

여기서는 현재 디렉토리에서 ./dir1 , ./dir2./dir3 을 제외합니다 find 표현식에서 기준에 따라 작동하는 작업이기 때문입니다. -path dir1 -o -path dir2 -o -path dir3 ( dir1 또는 dir2 인 경우 또는 dir3 ), ANDed with type -d .

모든 레벨에서 디렉토리 이름을 제외하려면 -name 사용하십시오.

find . -type d \( -name node_modules -o -name dir2 -o -path name \) -prune -false -o -name '*.json'
  
출처 : https://stackoverflow.com/questions/4210042/how-to-exclude-a-directory-in-find-command
728x90
반응형