2011-02-10 98 views

回答

7
grep -l "abc" * 

如果你想递归,

grep -R -l "abc" * 

如果你有红宝石(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 
3

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

+0

在那里有`find/-type f`还是`grep`只是忽略目录等等? – 2011-02-10 03:32:43

+0

我觉得`grep`默默忽略那些不是普通文件的,结果不会变化。可能会加速,但对于我的`find | grep“的作品太小,无法察觉可能的速度差异。 :) – vpit3833 2011-02-10 03:43:46

相关问题