繁体   English   中英

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

[英]Can I use grep to find a file including a particular string?

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

grep -l "abc" *

如果您要递归,

grep -R -l "abc" *

如果您有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

find / -name * | xargs grep -nH abc - find / -name * | xargs grep -nH abc -查找所有具有字符串“ abc”的文件,并显示文件名以及出现“ abc”的行号。 这是你想要的?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM