• linux命令详解之-find精确查找和高级使用


    格式:find    [目录]   [条件1]

    –   常用条件表示:

    -type  类型(f、d、l)

    -name  "文档名称"

    -size  +|-文件大小(k、M、G)

    -user  用户名

    -mtime  修改时间

       -type  类型(f文本文件、d目录、l快捷方式)

    [root@A /]# find  /boot  -type  d

    [root@A /]# find  /opt  -type  d

    [root@A /]# find  /etc  -type  l  

    [root@A /]# find  /boot  -type  f

       -name  "文档名称"

    ]# find  /etc/  -name  "passwd"

    ]# find  /etc/  -name  "*tab"

    ]# find  /etc/  -name  "*.conf"

    ]# find  /etc/  -name  "group"

    ]# find  /etc/  -name  "fstab"

    ]# find  /etc/  -name  "hosts"

    ]# find  /etc/  -name  "shadow"

    ]# find  /etc/  -name  "*tab"   |  wc  -l

    ]# find  /etc/  -name  "*.conf"  |  wc  -l

    ]# find  /etc/  -name  "*.conf"  |  cat  -n

    ]#  wc  -l    /etc/passwd   #统计有多少行

    ]#  cat  -n   /etc/passwd

    [root@A /]# mkdir   /mnt/nsd01

    [root@A /]# mkdir   /mnt/nsd02

    [root@A /]# touch   /mnt/nsd03.txt

    [root@A /]# find /mnt/  -name  "nsd*"

    [root@A /]# find /mnt/  -name  "nsd*"  -type d

    [root@A /]# find /mnt/  -name  "nsd*"  -type f

      -size  +或- 文件大小(k、M、G)

    [root@A /]# find  /boot/  -size  +300k

    [root@A /]# find  /boot/  -size  +10M

    [root@A /]# find  /boot/  -size  +1M

       -user  用户名 (按照数据的所有者)

    [root@A /]# useradd  natasha  #创建用户

    [root@A /]# find  /home/  -user  natasha

    [root@A /]# find  /   -user  natasha

    /proc:内存的数据,不占用硬盘空间

       -mtime  修改时间 (所有的时间都是过去时间)

        -mtime  +90  #90天之前的数据(三个月之前)

        -mtime  -90   #最近90天之内的数据

    [root@A /]# find  /root  -mtime  +90

    [root@A /]# find  /root  -mtime  -10

    find高级使用

    处理find找到的数据,每查找的一个就传递一次

    –   find  [范围]  [条件]  -exec  处理命令  {}   \;

    -exec额外操作的开始

    {} 永远表示前面find查找的结果

    \;  额外操作的结束

    ]# find /boot/ -size +10M

    将/boot目录下大于10M的数据,复制到/mnt

    ]# find /boot/ -size +10M -exec  cp  {}  /mnt  \;

    ]# ls  /mnt/

    案例2:查找并处理文件

    1.        利用find查找系统中用户 student 拥有的数据,并且必须是文件,把它们拷贝到 /root/findfiles/ 文件夹中

    ]# useradd  student     

    ]# mkdir  /root/findfiles

    ]# find  /  -user student  -type  f

    ]# find  /  -user student  -type  f  -exec cp  {}  /root/findfiles  \;

    ]# ls  -A  /root/findfiles/
     

  • 相关阅读:
    MYSQL02高级_目录结构、默认数据库、表文件、系统独立表空间
    怎么批量保存网页图片-快速批量保存网页的方法
    [Java SE] 经典问题:超出Java Long型(8字节/64位)的二进制比特流数据如何进行大数的数值计算?
    htmx-使HTML更强大
    多模态论文阅读-LLaVA
    RSA网络安全密码学?
    Windows10安装Ubuntu子系统及子系统安装openjdk8
    【Linux】内核同步
    【数字IC验证快速入门】4、熟悉数字IC验证中常用的Linux基本操作
    《铸梦之路》帧同步卡牌放置手游(斗罗大陆武魂觉醒、上古王冠)
  • 原文地址:https://blog.csdn.net/rqaz123/article/details/126116272