2014-10-20 3 views
1

디렉토리에서 모든 .html 파일을 찾고 일부 파일을 무시하고 싶습니다.txt 파일에서 'find'터미널 명령을 읽습니다.

$ find /Volumes/WORKSPACE/MyProject/ -name '*.html' ! -name 'MyFile.html' 

위의 명령은 MyFile.html 만 무시합니다. 그러나 나는 파일의 목록을 무시하고 하나의 txt 파일에 무시 파일을 유지하고 싶습니다.

MyFile1.html  
MyFile1.html 
MyFile2.html 
MyFile2.html 

위의 내용은 txt 파일 내용입니다.

나는 무시할 파일 목록을 단일 txt 파일에서 유지 관리하고 txt 파일을 찾기 명령에 사용하고 싶습니다.

상담하십시오. 미리 감사드립니다.

답변

2

파일에서 배열과 같은 것을 작성한 다음 find 구문으로 사용해야합니다. 즉

#!/bin/bash 
while IFS= read -r file; do 
    arr+=(-name "$file" -o) 
done < list_of_filenames_to_omit.txt 

#remove trailing -o 
unset arr[$((${#arr[@]}-1))] 

if ((${#arr[@]}!=0)); then 
    find /Volumes/WORKSPACE/MyProject/ -name '*.html' ! \("${arr[@]}" \) 
else 
    #list_of_filenames_to_omit.txt is empty 
    find /Volumes/WORKSPACE/MyProject/ -name '*.html' 
fi 
관련 문제