
RHEL v6.x
현재 디렉토리에서 특정 디렉토리 구조를 검색하기 위해 Linux 명령을 찾고 있습니다 .
단일 디렉토리에 대해서는 작동하지만 디렉토리 구조에 대해서는 작동하지 않는 현재 디렉토리의 특정 단일 디렉토리를 검색하는 아래 명령을 알고 있습니다.
일하고 있는:
find /home/dir1/* -name "def"
작동 안함:
find /home/dir1/* -name "abc/def"
또한 아래 명령을 시도했지만 이 디렉터리 내부의 파일도 나열됩니다. 하지만 이 디렉터리 내부의 파일을 나열하고 싶지 않습니다. 나는 이 abc/def
디렉토리 구조를 가진 모든 디렉토리의 전체 경로만 나열하고 싶습니다 .
locate abc/def/
누구든지 나를 도와주세요.
미리 감사드립니다.
답변1
테스트 -name
는 마지막 경로 구성 요소와만 일치합니다. 당신 과 같은 것을 일치시키려면 다음이 abc/def
필요합니다 -path
:
$ mkdir -p somedir/otherdir/abc/def/ghi
$ find somedir -path '*/abc/def'
somedir/otherdir/abc/def
답변2
이건 어때.
find /home/dir1/ -type d | grep 'abc/def'
또는 특정 깊이까지만 디렉토리를 나열하려는 경우.
find /home/dir1/ -maxdepth 2 -type d | grep 'abc/def'
-d - directory
-maxdepth levels of directories below the starting-points.
답변3
tree <base dir>
-L level
Max display depth of the directory tree.
-P pattern
List only those files that match the wild-card pattern.