Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在linux中创建用于搜索文件内部文本的别名_Linux_Shell_Grep - Fatal编程技术网

如何在linux中创建用于搜索文件内部文本的别名

如何在linux中创建用于搜索文件内部文本的别名,linux,shell,grep,Linux,Shell,Grep,我想使用自定义别名递归搜索目录中的文本。 现在我用这个 grep -r "text to search" /var/www/sites 我先要 仅搜索特定文件,如仅搜索html、仅搜索php文件 我还想要文件的行号 我想将命令的别名设置为myalias 所以从命令行我只使用这个 myalias要搜索的文本(不带引号) 这可能吗把它放在你的~/.bashrc中: wwwgrep() { find /var/www/sites -name '*.php' -o -name '*.html

我想使用自定义别名递归搜索目录中的文本。 现在我用这个

grep -r "text to search" /var/www/sites
我先要

  • 仅搜索特定文件,如仅搜索html、仅搜索php文件
  • 我还想要文件的行号
  • 我想将命令的别名设置为
    myalias
    所以从命令行我只使用这个
  • myalias要搜索的文本(不带引号)


    这可能吗

    把它放在你的~/.bashrc中:

    wwwgrep() { 
        find /var/www/sites -name '*.php' -o -name '*.html' -exec grep -Hn "$1" {} \;
    }
    
    然后


    把这个放在你的~/.bashrc中:

    wwwgrep() { 
        find /var/www/sites -name '*.php' -o -name '*.html' -exec grep -Hn "$1" {} \;
    }
    
    然后


    有个错误,现在没事了。用
    -p
    开关而不是
    -n
    键入
    grep
    在编辑完文件后,您必须
    source~/.bashrc
    。或者注销并登录,以便执行.bashrc。@sputnick我发现它没有告诉我文件名,只有行号和匹配的文本。你能看一看吗?请按此编辑。但是在
    man grep
    中搜索10秒后,您会得到通知。出现错误,现在可以了。用
    -p
    开关而不是
    -n
    键入
    grep
    在编辑完文件后,您必须
    source~/.bashrc
    。或者注销并登录,以便执行.bashrc。@sputnick我发现它没有告诉我文件名,只有行号和匹配的文本。你能看一看吗?请按此编辑。但是在
    man grep
    中搜索10秒,您会得到通知。
    exec bash