zoukankan      html  css  js  c++  java
  • find

    有关find -mtime这个参数的使用确实是我以前犯过错误。今天又有人问到我这个问题,我觉得有必要把这个问题在这里记录下来。
    mtime参数的理解应该如下:
    -mtime n 按照文件的更改时间来找文件,n为整数。
    n表示文件更改时间距离为n天, -n表示文件更改时间距离在n天以内,+n表示文件更改时间距离在n天以前。
    例如:
    -mtime 0 表示文件修改时间距离当前为0天的文件,即距离当前时间不到1天(24小时)以内的文件。
    -mtime 1 表示文件修改时间距离当前为1天的文件,即距离当前时间1天(24小时-48小时)的文件。
    -mtime+1 表示文件修改时间为大于1天的文件,即距离当前时间2天(48小时)之外的文件
    -mtime -1 表示文件修改时间为小于1天的文件,即距离当前时间1天(24小时)之内的文件

    为什么-mtime+1 表示文件修改时间为大于1天的文件,即距离当前时间48小时之外的文件,而不是24小时之外的呢?
    因为n值只能是整数,即比1大的最近的整数是2,所有-mtime+1不是比当前时间大于1天(24小时),而是比当前时间大于2天(48小时)。
     

    zzx@zzx120:~/zzx1/test$ find .  -maxdepth  1  -name "[0-9]*"          #查找当前目录下(不包含子目录下的文件) 数字开口的文件,  ##find默认查找包含子目录
    ./1.txt
    ./1.sh
    ./11.txt
    ./3.txt
    ./4.txt
    ./2.txt

    zzx@zzx120:~/zzx1/test$ find .  -name  file -prune  -o -name a -prune  -o   -name "[0-9]*"   -print          当前目录下不包含file和a文件夹或文件  查找 0-9开头的文件或目录或……   -name后面可再加

                                                                                                                                                              包含a的文件夹不包含a的文件: -name a -type f

    -type

    -name

    -user    删掉user之后就只有uid

    -uid 

    -gid

    -nouser 没有属主

    -nogroup 没有属组

    -type

    -size   k M G   +|-                          find .  -size 1M  结果会把不足0M到1M的也找出来    -size 10k  找出9到10k的文件   -size -10k 小于10的文件  -size +10k  大于10k的文件

    精确查找应该用

    -mtime    [+|-]#

    -ctime

    -atime

    -mmin    [+|-]#

    -cmin

    -amin

    查多种文件  

    -a   and

    -o   or

    -not 或者 !        非

    -perm   mode    匹配文件权限    -perm 644 精确匹配(777不能找出)   -perm -644  文件权限能完全包含此mode才符合  (777包含644所以能被找出)         -perm /644  任意一位权限匹配就满足(600  004  040 都能找出)

    -exec  COMMAND {}  ;        find ./ -perm -006 -exec chmod o-w {} ;      find ./ -perm -020 -exec mv {} {}.new ;         #修改文件名 添加.new

    -xargs      find /etc -size +1M | xargs echo >> /tmp/etc.largefile  ;
    zzx@zzx103:~$ sudo  find . -name "*.txt"  -o  -name "*.sh"

    Linux下find一次查找多个指定文件或者排除某类文件,在 GREP 中匹配多个关键字的方法
    (1)Linux下find一次查找多个指定文件:
    查找a.html和b.html

    1. find . -name "a.html"  -name "b.html"  


    find . -regex '.*.txt|.*.doc|.*.mp3'   #正则表达式 find . -regex '.*.sh|.*.txt'     #  find . -regex '.*.sh|.*.txt'(这种就是错的 .没有转义表示任务字符)   #         .*:      ".*"  表示所有字符,因为.表示任意一个字符,*是前面字符的重复。      .* 来表示任意长度字符串.

    1. find . -regex '.*.txt|.*.doc|.*.mp3'  
    2. ./a.txt  
    3. ./a.doc  
    4. ./a.mp3  


    (2)排除某些文件类型:
    排除目录下所有以html结尾的文件:

    1. find . -type f -name "*.html"    
    1. find . -type f ! -name "*.html"       
    2. ./ge.bak.02.09  
    3. ./ge.html.changed.by.jack  
    4. ./a.txt  
    5. ./a.doc  
    6. ./a.mp3  


    (3)排除多种文件类型的示例:

    1. find . -type f ! -name "*.html" -type  f ! -name "*.php" -type  f ! -name "*.svn-base"  -type  f ! -name "*.js"  -type  f ! -name "*.gif"  -type  f ! -name "*.png"  -type  f ! -name "*.cpp"  -type  f ! -name "*.h"  -type  f ! -name "*.o"  -type  f ! -name "*.jpg"  -type  f ! -name "*.so"  -type  f ! -name "*.bak"  -type  f ! -name "*.log"   


    (3)在 GREP 中匹配多个关键字的方法:
    grep查找多个数字的文件:
    -r 递归,-E:正则  -l:只显示文件名

    1. root@116.255.139.240:~/a# grep -r -E '0341028|100081|10086|10001' *  
    2. a.txt:100081  
    3. b.txt:10086  
    4. c/cc.txt:0341028  
    5. c/cc.txt:100081  
    6. c/cc.txt:10086  
    7. c/cc.txt:10001  
    8. c.txt:10001  
    9. d.txt:0341028  
    1. grep -r  -E -l '0341028|100081|10086|10001' *     
    2. a.txt  
    3. b.txt  
    4. c/cc.txt  
    5. c.txt  
    6. d.txt  


    多种类型文件示例:

    1. find . -name "*.html" -o -name "*.js"|xargs grep -r "BusiTree"   



    用Awk:

      1. find . -name "*.php"|awk '{print "cat " $0 " |grep -H dbsys.mxxxx.justwinit.cn"}'|sh 
  • 相关阅读:
    execute,executeQuery,executeUpdate的区别是什么?
    JDBC访问数据的基本步骤是什么
    什么是JDBC,在上面时候会用到它
    Java 为每个原始类型提供了哪些包装类型:
    Java 为每个原始类型提供了哪些包装类型:
    JDBC访问数据库的基本步骤是什么?
    String 类的常用方法都有那些?
    == 和 equals 的区别是什么
    查询所有课程成绩小于60分的同学的学号、姓名;
    什么是JDBC的最佳实践?
  • 原文地址:https://www.cnblogs.com/hanxing/p/4157858.html
Copyright © 2011-2022 走看看