2017-06-13 4 views
-2

linuxコマンドを使用して特定の文字列を含むディレクトリからファイルをリストする必要があります。linuxコマンドを使用して特定の文字列を含むファイルを一覧表示する方法

+1

は、ファイル名や内部に含まれているコマンドを使用しますか?テキストファイル? –

+0

[Linuxで特定のテキストを含むすべてのファイルを見つけるにはどうすればよいですか?](https://stackoverflow.com/questions/16956810/how-do-i-find-all-files-containing-specific-text-on -linux) – xiawi

答えて

0

あなたがこれを使用すると、特定の文字列を含むファイル名(複数可)を一覧表示したい場合は、文字列

を含む行番号を持つファイルの名前を表示します

grep -nr <string> <path to the directory> 

を行うことができ、その後

を行います
find <path to the directory> -iname <string_pattern> -type f 
0

文字列が環境変数STRにあり、ディレクトリdir/を検索しているとします。あなたは、文字列を含むファイルを検索する場合

find dir/ -type f -name "*${STR}*" 

find dir/ -type f -exec grep -l $STR {} \; 

をしかし、これはこのコマンドは、一致する文字列を含むファイルを検索しますhere

0

を説明しているあなたは行うことができます。 しかし、少し余分に追加して、execがファイルをリストします。

コマンド

find <your/dir/> -name "string_to_search*" -type f -exec ls -l {} \; 

またはこのコマンドは、ディレクトリ内のすべてのCファイルが一覧表示されます。ファイル内の一致する文字列を見つけるために、findコマンドを使用して

find <your/dir/> -name "*.c" -type f -exec ls -l {} \; 

ここ
find -type f | xargs grep 'text-to-find-here' 

/はすべてのdirsで検索を意味

find/-type f | xargs grep 'text-to-find-here' 

または

grep -r "string to be searched" /path/to/dir 
+0

ありがとうございますが、ファイルをリストしていません – Deepi

+0

ディレクトリからファイルをリストしたいですか? – LethalProgrammer

+0

特定の文字列を含むディレクトリからファイルをリストしたいとします。ファイルに57690が含まれている場合は、 – Deepi

0

grep -inr <string> /path/to/directory 
i - Ignore case sensitivity. 
n - Display the matched lines and their line numbers. 
r - Read all files under each directory, recursively 
関連する問題