zoukankan      html  css  js  c++  java
  • find 命令 查找

    find 查找文件和目录

    find /home -name ""

    find 后接查找的目录,-name 后指定需要查找的文件名 文件名可以用*表示所有
    find /home -name "*.txt" 查找/home目录下下,所有以.txt结尾的文件或者目录

     

    find /home -name "*.txt" -type f

    -type 查看文件类型
    f 文件
    d 目录

     

    - exec = xargs

    find /home -name "abc.txt" -type f -exec cp {} /root ;


    找到这个文件 拷贝到/root/目录下

    -mtime 按修改时间查找

    +4 4天以前

    4 第三天

    -3 最近4天

    find / -mtime +3        // 搜索三天之内创建或修改的文件
    
     
    find /home -name "*.txt"  -type f  -mtime +70   
    查看/home 下 70天前 以.txt 后缀的文件

    查找/log/目录下 删除 以.log后缀 15天以前修改过的的文件

    find /log -type f -name "*.log" -mtime +15| xargs rm -f

    查找/log目录下 删除修改日期在30天以前,且以test名称结尾的目录

    find /log -type d -name "test" -mtime +30 |xargs rm -rf
    [root@localhost ~]# find / -name test       # 搜索根目录下名字为test的文件
    [root@localhost ~]# find / -name "test*"    # 如果使用通配符必须加上引号
    [root@localhost ~]# fine / -iname test      # 搜索根目录下名字为test的文件(不区分大小写)
    [root@localhost ~]# find / -type f          # 搜索根目录下的文件
    [root@localhost ~]# find / -type d          # 搜索根目录下的目录
    [root@localhost ~]# find / -amin -10        # 搜索十分钟之内被访问过的文件
    [root@localhost ~]# find / -amin +10        # 搜索十分钟之前被访问过的文件
    [root@localhost ~]# find / -mmin -10        # 搜索十分钟之内被修改过的文件
    [root@localhost ~]# find / -mmin +10        # 搜索十分钟之前被修改过的文件
    [root@localhost ~]# find / -atime -10       # 搜索十天之内被访问过的文件
    [root@localhost ~]# find / -atime +10       # 搜索十天之前被访问过的文件
    [root@localhost ~]# find / -mtime -10       # 搜索十天之内被修改过的文件
    [root@localhost ~]# find / -mtime +10       # 搜索十天之前被修改过的文件
    [root@localhost ~]# find / -size +100k      # 搜索根目录下大于100k的文件
    [root@localhost ~]# find / -name test -exec rm {} ;             # 搜索名字为test的文件并删除
    [root@localhost ~]# find / -name test -exec mv {} {}.bak ;      # 搜索名字为test的文件并改名
    [root@localhost ~]# find / -name test | xargs rm                 # 搜索名字为test的文件并删除
    [root@localhost ~]# find / -name test | xargs rm -f
    [root@localhost ~]# find / -name test | xargs -i mv {} {}.bak    # 搜索名字为test的文件并改名
    [root@localhost ~]# find / -type f ! -name "*.txt"               # 搜索的结果排除txt结尾的文件
    [root@localhost ~]# find / -type f ! ( -name "*.txt" -o -name "*.sh" )    # 搜索的结果排除txt结尾或sh结尾的文件,注意括号前要加转义符

    mv find找到 /data目录 下所有以.txt后缀的文件 移动到 /tmp下

    mv `find /data type -f -name "*.txt" ` /tmp/

     !取反

    删除/tmp/目录下 除 passwd以外的其他文件

    在 -name "passwd"前面   加上! 代表对这段取反

    find /tmp -type f ! -name  "passwd" -exec rm {} ;

    在某个路径下查找所有包含“upload file”字符串的文件

    find . -name '*' -type f| xargs grep 'upload file'

  • 相关阅读:
    [转载] Oracle之内存结构(SGA、PGA)
    此生若能得幸福安稳,谁又愿颠沛流离
    隐式转换和显式转换及强制转换的区别
    System.Web.Optimization对脚本和样式表的操作
    js 时间日期函数小结
    jQuery 中bind(),live(),delegate(),on() 区别
    Html.Partial()传值的问题
    js过滤HTML标签以及 
    select ROW_NUMBER() over(PARTITION BY InfoType order by NewsID)as rowid from News
    Asp.net单点登录解决方案
  • 原文地址:https://www.cnblogs.com/mingerlcm/p/7838065.html
Copyright © 2011-2022 走看看