【问题标题】:Bash find line of code in a file/files, in directoryBash 在目录中的文件/文件中查找代码行
【发布时间】:2016-06-04 22:01:31
【问题描述】:

我怎样才能找到这条线:

 print("hello world)"

在目录 x/y/z 中,其中文件/文件可以在 x 的树的任何分支中(目录 x 有很多子文件夹

【问题讨论】:

    标签: linux bash shell directory


    【解决方案1】:

    你可以从x的父目录使用递归grep

    grep -FR 'print("hello world)"' x/*
    

    【讨论】:

    • 由于您要查找的行看起来像一些代码,您可能有兴趣使用标志 '--include': grep -FR --include '.c' 'print( "hello world")' x/ 以查找 c 代码文件为例。
    • 是的,我也会包含--include=,但没有提到要搜索的文件扩展名
    • 是否使用了F 标志,因此不需要转义?
    • Yes F 用于固定字符串,因此不将模式视为正则表达式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多