find精确查找

find精确查找

格式: find 【目录】 【条件】
-常用条件表示:
	-type 类型 (f 、d、 l)
	-name '文档名称'
	-size +|- 文件大小 (k、M 、G)
	-user 用户名
	-mtime 修改时间

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

查找/boot里面的目录

root@host50 ~]#  find  /boot  -type  d
/boot
/boot/efi

查找/etc快捷方式

[root@host50 ~]# find  /etc  -type  l 
/etc/mtab
/etc/alternatives/libnssckbi.so.x86_64
/etc/alternatives/ld
/etc/alternatives/mta

查找文件名字 :-name

[root@web33 ~]# find  /etc/  -name  "*tab"
/etc/fstab
/etc/crypttab
查找含有名字为*tab
查找*tab的 一共有多少行
[root@web33 ~]# find  /etc/  -name  "*tab"   |  wc  -l
9
查找*tab的每一行并且把行号标记出来
[root@web33 ~]# find  /etc/  -name  "*tab"   | cat -n
     1	/etc/fstab
     2	/etc/crypttab

查找文件大小-size +或- 文件大小(k、M、G),文件大小前面+代表大于;-代表小于

[root@openstack ~]# find  /boot/  -size  +300k
/boot/grub2/fonts/unicode.pf2
/boot/System.map-3.10.0-862.el7.x86_64
/boot/vmlinuz-3.10.0-862.el7.x86_64
[root@openstack ~]# find  /boot/  -size  +10M
/boot/initramfs-0-rescue-c67cdc077da34a5f9ebef3d6e15ae759.img
/boot/initramfs-3.10.0-862.el7.x86_64.img

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

[root@openstack ~]# useradd natasha
[root@openstack ~]# find /home -user natasha
/home/natasha
/home/natasha/.bash_logout
/home/natasha/.bash_profile
/home/natasha/.bashrc
#/proc:内存的数据,不占用硬盘空间

-mtime 修改时间 (所有的时间都是过去时间)
-mtime +90 # 90之前的数据
-mtime -90 #最近90天之内的数据

[root@openstack ~]# find /root -mtime -10
/root
/root/.bash_history
/root/.ssh/known_hosts
/root/.viminfo

find高级使用

处理find找到的数据,每查找的一个就传递一次
-find [范围] 【条件】 -exec 处理命令 {}  \;
-exec额外操作的开始
{}永远表示前面find查找的结果
\;额外操作的结束
[root@openstack ~]# find /boot/ -size +10M
/boot/initramfs-0-rescue-c67cdc077da34a5f9ebef3d6e15ae759.img
/boot/initramfs-3.10.0-862.el7.x86_64.img
[root@openstack ~]# find /boot/ -size +10M  -exec cp {} /mnt \;
[root@openstack ~]# ls /mnt
initramfs-0-rescue-c67cdc077da34a5f9ebef3d6e15ae759.img
initramfs-3.10.0-862.el7.x86_64.img

查找并处理文件
1.利用find查找数据,所有者未student 并且必须是文件,把它们拷贝到 /root/findfiles/ 文件中

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值