zoukankan      html  css  js  c++  java
  • find tar排除指定文件或目录操作及查找文件内容关键字

     1.find查找排除单个目录

    查找当前目录或者子目录下所有.txt文件,但是跳过子目录sk

    find . -path "./sk" -prune -o -name "*.txt" -print

    find . -type f -executable ! -path "./.git/*"

    • .:在当前目录下查找

    • -type f:仅查找一般文件

    • -executable:文件具有可执行权限

    • ! -path "./.git/*":这里是关键,! 的作用是排除其后 -path 所跟的目录

    2.find查找排除多个目录

    find / path/home/opath/root -prune -nouser -type f -exec ls -l {} ;

    find /usr/sam ( -path /usr/sam/dir1 -o -path /usr/sam/file1 ) -prune -o -print

    3.tar根据文件列表压缩指定文件

    tar -czv -T /opt/src/downLoad_list.txt -f downLoad_list.txt.tar.gz
     
      -T, --files-from=FILE      get names to extract or create from FILE
          --unquote              unquote filenames read with -T (default)
      -X, --exclude-from=FILE    exclude patterns listed in FILE
     
    -T 指定需要压缩的文件列表,只压缩文件列表里的文件
    -f 指定压缩文件名及路径
    -X 排除指定文件,不进行压缩

    4.find查找指定文件内容包含特定关键字

    find . -type f -name '*.jsp' -exec awk 'BEGIN{ FS=" "; RS="" } /关键字1/&&/关键字2/ {print FILENAME}' {} ;

    awk查询的是这俩关键字同时出现在find查询的文件中的,是与的关系

     
  • 相关阅读:
    适者生存还是强者生存
    写给十岁的清为
    毕业后的十年
    Python3 字符编码
    线段树模板
    F
    E
    D
    C
    B
  • 原文地址:https://www.cnblogs.com/zhanmeiliang/p/6394300.html
Copyright © 2011-2022 走看看