다음과 같은 디렉토리 구조가 있습니다.
data
|___
|
abc
|____incoming
def
|____incoming
|____processed
123
|___incoming
456
|___incoming
|___processed
Data 디렉터리 내의 모든 폴더에는 들어오는 하위 폴더가 있습니다. def / incoming 및 456 / incoming dirs를 제외한 모든 폴더와 하위 폴더에서 모든 파일을 가져오고 싶습니다. 다음 명령으로 시도했습니다.
find /home/feeds/data -type d \( -name 'def/incoming' -o -name '456/incoming' -o -name arkona \) -prune -o -name '*.*' -print
그러나 예상대로 작동하지 않습니다.
라비
답변
이것은 작동합니다 :
find /home/feeds/data -type f -not -path "*def/incoming*" -not -path "*456/incoming*"
설명:
find /home/feeds/data
: 지정된 경로에서 재귀 적으로 찾기 시작-type f
: 파일 만 찾기-not -path "*def/incoming*"
:def/incoming
경로의 일부로 포함하지 마십시오.-not -path "*456/incoming*"
:456/incoming
경로의 일부로 포함하지 마십시오.
답변
문서화를 위해서 : search’n’skip 별자리가 많기 때문에 더 깊이 파야 할 수도 있습니다. 당신이 기대하는 것을하지 않는 prune
동안 당신의 친구 라는 것이 밝혀 질 수도 있습니다 -not -path
.
따라서 이것은 디렉토리를 제외하는 15 개의 찾기 예제의 귀중한 예입니다.
http://www.theunixschool.com/2012/07/find-command-15-examples-to-exclude.html
초기 질문에 연결하려면 finally 제외는 다음과 같이 저에게 효과적이었습니다.
find . -regex-type posix-extended -regex ".*def/incoming.*|.*456/incoming.*" -prune -o -print
그런 다음 하나의 파일을 찾고 여전히 경로를 제외하려면 | grep myFile.txt
.
또한 찾기 버전에 따라 다를 수 있습니다. 내가 참조:
$ find -version
GNU find version 4.2.27
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION SELINUX
답변
-name
전체 경로가 아닌 파일 이름 만 일치합니다. 당신은 사용할 -path
당신이 좋아하는 디렉토리를 치기되는 부품 대신 def/incoming
.
답변
find $(INP_PATH} -type f -ls |grep -v "${INP_PATH}/.*/"
답변
이 방법을 따라 찾기에서 디렉토리를 제외하십시오. 명령 :
find . \( -name ".git" -o -name "node_modules" \) -prune -o -print