2017-07-14 13 views
0

特定の正規表現と一致する複雑なディレクトリ構造内のファイルのリストを探したいと思います。たとえば、ファイル名に_test_file_を持つファイルです。ツリーを使って特定のファイルを見つける方法

ツリー-P '_tree_file_':

私はほとんど成功し、次のコマンドを試してみました。

これは、0個のファイルを返します。 findを使う解決策があるようですが、可能であればtreeを使いたいと思います。

ありがとうございます!

アキ

+0

を明確にしてください:あなたは、名前 '_test_file_'が含まれている(その場合には、' find'を使用)のファイルにしたいですか?または内容に '_test_file_'という文字が含まれているファイルを探したいでしょうか(その場合は' grep -r'を使います)? – John1024

+0

上記を編集しましたか?findを使用するのが最適です –

答えて

2

manページから:

-P pattern 
     List only those files that match the wild-card pattern. Note: 
     you must use the -a option to also consider those files begin‐ 
     ning 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. 

あなたのコマンドtree -P '_tree_file_'の出力は正確に "_tree_file_" と一致する名前のファイルになります。

あなたはあなたの要求のためのワイルドカードを使用しようとする場合があります。

$ tree -P '*_tree_file_*' 
関連する問題