Linux下find命令的使用(命令+案例)

一、find的作用?

•递归式查找
•根据预设的条件递归查找对应的文件

二、find使用方法

– find [目录] [条件1]…

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

代码如下:

[root@localhost ~]# find   /home    -type   f
[root@localhost ~]# find   /root    -type   f

[root@localhost ~]# find   /home    -type   d
[root@localhost ~]# find   /root    -type   d

[root@localhost ~]# find   /etc    -type   l

-name “名称”

代码如下:

[root@localhost ~]# find  /etc/   -name   "*.conf"

[root@localhost ~]# find  /etc/    -name   "*tab*"

[root@localhost ~]# find  /etc/   -name   "passwd"

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

[root@localhost ~]# find   /boot/   -size  +20M

[root@localhost ~]# find   /boot/   -size  -10M

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

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

[root@localhost ~]# useradd  wxr  #新建用户
[root@localhost ~]#	find   /home    -user   zhangsan

-mtime 修改时间 #都是过去时间

三个月之前的数据:
[root@localhost ~]# find   /root    -mtime   +90

查找最近一天内:
[root@localhost ~]# find   /root    -mtime   -1

三、find高级使用处理查找的内容

案例:查找并处理文件
1. 利用find查找所有用户 student 拥有的必须是文件,把它们拷贝到 /root/findfiles/ 文件夹中

[root@localhost ~]# useradd   student
[root@localhost ~]# mkdir  /root/findfiles

[root@localhost ~]# find   /  -user  student  -type  f
[root@localhost ~]# find / -user student  -type f  -exec cp {}  /root/findfiles/  \;
[root@localhost ~]# ls  -A  /root/findfiles/

• 操作方法:
find [范围] [条件] -exec 处理命令 {} ;

– -exec :额外操作开始
– {} :find查询的结果
– ; :额外操作结束
– 每找到一个符合条件的数据,直接传输给-exec,每次只传输一个参数

  • 8
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值