
저는 다소 큰 파일 시스템을 가지고 있으며, String 을 포함하는 파일 시스템의 특정 영역에서 모든 파일과 디렉터리를 찾고 ActionListeener
이를 위해 를 사용하고 싶다고 가정해 보겠습니다 tree
. 그렇다면 다음과 같이 하세요.
tree ~/ | grep ActionListeener
결과는 다음과 같습니다:
│ │ │ └── ActionListeener.class
│ │ └── ActionListeener.java
이제 이러한 파일이 내 파일 시스템의 좀 더 깊은 어딘가에 존재한다는 것을 알고 있지만 어떤 폴더에 하위 폴더가 포함되어 있는지, 하위 폴더가 포함되어 있는지 등은 알 수 없습니다.
그래서 정말로 제 질문은, 해당 문자열이 포함된 특정 파일로 연결되는 폴더와 경로를 표시하기 위해 트리 명령(출력을 다른 것으로 파이프하여)을 어떻게 얻을 수 있습니까?
OS 정보:
Description: Ubuntu 15.04
Release: 15.04
패키지 정보:
tree:
Installed: 1.7.0-3
Candidate: 1.7.0-3
Version table:
*** 1.7.0-3 0
500 http://gb.archive.ubuntu.com/ubuntu/ vivid/universe amd64 Packages
100 /var/lib/dpkg/status
답변1
tree
의 패턴 일치( -P
)를 다음과 함께 사용하십시오 --prune
.
$ tree
.
├── archlinux-simplyblack
│ ├── angle-down.png
│ ├── archlinux.png
# snip
├── reboot.png
├── shutdown.png
└── theme.conf
8 directories, 78 files
$ tree -P 'reboot*' --prune
.
├── maui
│ └── reboot.png
└── maui-dark
└── reboot.png
2 directories, 2 files
에서man tree
:
-P pattern
List only those files that match the wild-card pattern. Note:
you must use the -a option to also consider those files
beginning with a dot `.' for matching. Valid wildcard
operators are `*' (any zero or more characters), `?' (any single
character), `[...]' (any single character listed between
brackets (optional - (dash) for character range may be used: ex:
[A-Z]), and `[^...]' (any single character not listed in
brackets) and `|' separates alternate patterns.
--prune
Makes tree prune empty directories from the output, useful when
used in conjunction with -P or -I. See BUGS AND NOTES below for
more information on this option.
답변2
-f
트리 옵션을 사용하세요 . 에서 man tree
:
-f 각 파일의 전체 경로 접두어를 인쇄합니다.
따라서 귀하의 명령은 다음과 같습니다:
tree -f ~/ | grep 'ActionListeener'
이는 줄의 어느 위치에서나 일치하므로 ActionListeener
이를 실행할 디렉터리를 정확하게 선택해야 합니다.
답변3
노력하다tree -P '<your_regex_or_file_name>' <tree_root_directory> --prune
귀하의 경우: tree -P 'ActionListeener' ~ --prune