zoukankan      html  css  js  c++  java
  • 每天一个linux命令(grep)

    grep----文本搜索工具

    格式:grep [参数]

    主要功能:

    1.匹配某个文件中的某段内容

    2.与ps连用,作为ps的搜索条件

    主要参数:

    -a:不忽略二进制数据

    -c:统计总共匹配出多少行

    [root@root home]# cat 1.txt
    123123
    123123
    123123
    [root@root home]# grep –c “11.txt
    3

    -n:将搜索出来的结果前面添加上行号

    [root@root home]# grep –n “31.txt
    1:123123
    2:123123
    3:123123

    -r :明确要求搜索文件夹下的子目录

    [root@root home]# grep1” test/*
    test/1.txt:123123
    test/1.txt:123123
    test/1.txt:123123
    test/2.txt:123123123123123123123123123123123
    grep: test/a: Is a directory --提示test/a是个目录
    grep: test/b: Is a directory --提示test/b是个目录
    [root@root home]# grep –r “1” test/*
    test/1.txt:123123
    test/1.txt:123123
    test/1.txt:123123
    test/2.txt:123123123123123123123123123123123
    test/a/3.txt:321321

    -l:显示匹配到内容的文件名(-L:显示没有匹配到的文件名)

    [root@root home]# grep -l –r “123”  test/*
    test/1.txt
    test/2.txt
    [root@root home]# grep -l –r “1”  test/*
    test/1.txt
    test/2.txt
    test/a/3.txt

    正则表达式:


    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~华丽的切割线~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • 相关阅读:
    P2731 骑马修栅栏 Riding the Fences
    P1351 联合权值
    [脚本]为所有节点挂载磁盘
    [转]expect的安装
    挂载磁盘linux
    [转]Mac 科研常用软件
    [转]error while loading shared libraries 错误解决办法总结
    linux安装SVN
    Java web项目在linux环境下自动编译和部署脚本
    个人所得税计算方法
  • 原文地址:https://www.cnblogs.com/hollyhock/p/10182166.html
Copyright © 2011-2022 走看看