
かなり大きなファイル システムがあり、ファイル システムの特定の領域で文字列 を含むすべてのファイルとディレクトリを検索したいとします。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