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/
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

rqaz123

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值