![특정 하위 디렉터리를 포함하지 않는 디렉터리 이름 찾기](https://linux55.com/image/159560/%ED%8A%B9%EC%A0%95%20%ED%95%98%EC%9C%84%20%EB%94%94%EB%A0%89%ED%84%B0%EB%A6%AC%EB%A5%BC%20%ED%8F%AC%ED%95%A8%ED%95%98%EC%A7%80%20%EC%95%8A%EB%8A%94%20%EB%94%94%EB%A0%89%ED%84%B0%EB%A6%AC%20%EC%9D%B4%EB%A6%84%20%EC%B0%BE%EA%B8%B0.png)
200개 이상의 WordPress 사이트가 있고 /home2/blogname/public_html/
플러그인 디렉토리 아래에 "better-wp-security"라는 하위 디렉토리가 없는 블로그를 찾아야 합니다. 예를 들면 다음과 같습니다./home2/blogname/public_html/wp-content/plugins/
그 이유는 "better-wp-security" 플러그인이 설치되지 않은 블로그를 알기 위해서입니다.
이 디렉토리가 있는 블로그에는 다음과 같은 내용이 표시됩니다.
/home2/blogname/public_html/wp-content/plugins/better-wp-security/
/home2/blogname
...그래서 해당 디렉토리가 없는 블로그(/)의 기본 디렉토리를 나열해야 합니다 .
어떻게 해야 하나요? .
답변1
를 사용하여 이 작업을 수행할 수 있지만 find
셸 루프를 사용할 수도 있습니다.
for dir in /home2/blogname/*
do
[ -d "$dir"/public_html/wp-content/plugins/better-wp-security ] || printf '%s is missing a public_html/wp-content/plugins/better-wp-security directory\n' "$dir"
done
GNU를 사용하여 다음을 찾으세요.
find /home2/blogname -mindepth 1 -maxdepth 1 -exec sh -c \
'test ! -d "$1"/public_html/wp-content/plugins/better-wp-security' findsh {} \; -print
이것은 /home2/blogname(/home2/blogname 자체는 제외) 아래의 모든 항목에서 작은 쉘 조각을 실행하지만 -mindepth 1
/home2/blogname/*(주어진)의 하위 디렉토리에서는 실행하지 않습니다 -maxdepth 1
. 이 조각은 지정된 디렉터리에 나열된 하위 디렉터리 구조가 있는지 확인하고 그렇지 않은 경우 test
이를 전달하고 인쇄합니다.