• Linux查找命令


    一、文件内容查找

      grep -lr '内容' 文件路径

      -l 匹配

      -L 不匹配

      -r 递归

    二、查找包含子路径的全路径

     (1)find 路径  -name '子路径' -type d

     find /home/odca -name 'xxx' -type d

     输出结果为:/home/odca/xxx

    (2)find ./ -name ‘*.xml’ -exec grep -i “log4j”{} ; -print

       在当前路径不区分大小写查找所有*.xml的文件里面含有"log4j"的内容行,并且print出来文件的路径

      

    (3)所要搜索的目录及其所有子目录。默认为当前目录。find默认递归指定目录。目录可以有多个,目录之间要用空格分开。

       find /etc /tmp /root -name XXX

    (4)-a,-o,-not的使用

       -a      连接两个不同的条件(两个条件必须同时满足):find /tmp -name "*.sh" -a -user root 

       -o     连接两个不同的条件(两个条件满足其一即可):find /tmp -name "*.sh" -o -user root

       -not 对条件取反的:find /tmp -not -user root

    (5)根据文件类型来查找文件

    -type 查找某一类型的文件 
     文件类型: f 普通文件 
                        d 目录 
                        l 符号链接文件 
                       c 字符设备文件 
                       p 管道文件 
                       b 块设备文件
                       s socket文件

    find /tmp -type s

    (6) 查找所有包含XXX的文件

    grep -H 'spring' *.xml 查找所有包含spring的xml文件

    (7)匹配查找行的前后内容

    grep  -5  'pattern'       打印匹配行的前后5行内容
    grep  -C 5  'pattern'   打印匹配行的前后5行内容
    grep  -A 5  'pattern'   打印匹配行的后5行内容
    grep  -B 5  'pattern'   打印匹配行的前5行内容

    (8)端口监听

    netstat -na|grep 3306

    netstat -lnt

    (9)find查询命令

    文件:find . -type f | xargs -i chmod 600 {}

    目录:find . -type d| xargs -i chmod 700 {}

    示例:在/目录中查找名称为test的所有目录----find / -type d -name test

     (10)压缩

        文件压缩:zip -r 文件名 需要压缩路径   zip -r contact.zip /data01/contact

        tar加密压缩:  tar -zcvf - sof.tgz | openssl des3 -salt -k 密码 | dd of=sof.des3

        tar解压:dd if=sof.des3 | openssl des3 -d -k 密码 | tar zxf -

    (11)动态修改jar包中的class文件

       A.查看XXX文件在jar包中的路径:jar tf x.jar| grep "XXX"

      B.以com/p1/p2/xxx.class文件替换掉xx.jar包中的文件:jar -uvf xx.jar 路径, 示例:jar -uvf X.jar com/p1/p2/xxx.class

      增量包中文件替换:

        解压:jar xvf xxx.jar

       压缩:jar cvf xxx.jar xxx/

       查看解压目录:jar tf xxx.jar |grep "xxx"

       替换jar包中的文件:jar uvf xxx.jar xxx/

      

  • 相关阅读:
    iOS开发UI篇—UITabBarController简单介绍
    iOS 开发 UI 搭建心得(一)—— 驾驭 StoryBoard
    The Swift Programming Language--语言指南--协议
    Swift 委托/代理设计模式
    Ping azure
    leetcode先刷_Maximum Subarray
    AsyncHandler
    HDU 1026 Ignatius and the Princess I 迷宫范围内的搜索剪枝问题
    Design Pattern Command 命令设计模式
    logstash高速入口
  • 原文地址:https://www.cnblogs.com/moonandstar08/p/5196725.html
Copyright © 2020-2023  润新知