• 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'

  • 相关阅读:
    VS调试技巧
    Git 分支
    WPF:如何高速更新Model中的属性
    Redis-4.0.11集群配置
    大压力下Redis参数调整要点
    统计UPD丢包工具
    查看Redis集群所有节点内存工具
    Redis集群命令行部署工具
    查看Redis集群主从对应关系工具
    Redis集群master选举时长测试
  • 原文地址:https://www.cnblogs.com/mingerlcm/p/7838065.html
Copyright © 2020-2023  润新知