我可以使用grep查找包含特定字符串的文件吗?

Don*_*Lun 0 unix linux grep

我可以使用grep查找包含特定字符串的文件吗?例如,在不知道文件名的情况下查找包含"abc"的文件.

kur*_*umi 7

grep -l "abc" *
Run Code Online (Sandbox Code Playgroud)

如果你想递归,

grep -R -l "abc" *
Run Code Online (Sandbox Code Playgroud)

如果你有Ruby(1.9+)

Dir["**/*"].each do |file|
  if test(?f,file)
   open(file).each do |line|
     if line[/abc/]
       puts "line: #{line}"
       puts "file: #{file}"
     end
   end
  end
end
Run Code Online (Sandbox Code Playgroud)