find命令用法

一.简介

linux的find命令用于查找指定目录中符合参数条件的文件,如果不设置任何参数,则find命令将在当前路径下查找子目录与文件。并且将查到的子目录和文件全部显示。

二.find命令常用参数

1)根据文件名及文件拥有人拥有组查找文件

环境:

touch /westos/file{1..5}

useradd westos

chown student.student /westos/file1

chown student.westos /westos/file2

chown root.student /westos/file3

chown westos.westos /westos/file4

监控窗口:

watch -n 1 ls -l /westos/

1.find /etc -name passwd                       ---查找/etc下名称中带有passwd的文件

 

2.find /etc -maxdepth 2 -name passwd ---查找/etc目录下名称中带有passwd的文件,且只查找两层

find /etc -maxdepth 1 -name passwd  ---查找/etc目录下名称为passwd的文件,且只向下查找一层

find /etc -maxdepth 2 -mindepth 2 -name  passwd      ---只在/etc下深度为2的目录中查找名称为passwd的文件

 

3.find /westos/ -user root               ---查找/westos/下拥有人为root的文件


find /westos/ -group root            ---查找/westos/下拥有组为root的文件


find /westos/ -user root -group student     ---查找/westos/下拥有人为root,拥有组为student的文件


find /westos/ -not -user student                  ---查找/westos/下拥有者不是student的文件


find /westos/ -user student -o -group westos    ---查找/westos/下拥有人是student或者拥有组为westos的文件,不加参数-o表示并且

2)根据文件的大小,文件类型及创建时间查找

监控窗口:

dd if=/dev/zero of=file1 bs=1 count=10240             ---文件/westos/file1大小为10M
dd if=/dev/zero of=file1 bs=2 count=20480             ---文件/westos/file2大小为20M
dd if=/dev/zero of=file1 bs=3 count=40960              ---文件/westos/file3大小为40M
watch -n 1 ls -l /westos/

实验窗口:


1.find -size 20k             ---查找本地大小为20k的文件


find -size -20k           ---查找本地文件小于20k的文件


find -size +20k          ---查找本地文件小于20k的文件

2.find /westos -type d          ---查找/westos下文件类型为目录的文件


find /westos -type f            ---查找/westos下文件类型为一般文件的

3.find -ctime 10    ---查找本地存在天数为10天的文件


find -ctime -10      ---查找本地存在天数少于10天的文件


find -ctime +10      ---查找本地存在天数大于10天的文件


find -cmin +|- 10    ---查找本地存在时间大于,等于,小于10分钟的文件

 

3)根据文件权限来查找文件

监控窗口:

rm -fr /westos/*
touch /westos/file{1..5}
chmod 000 *
chmod 404 file1
chmod 444 file2
chmod 644 file3
chmod 640 file4
watch -n 1 ls -lR /westos

查看/westos/下文件的权限,方便实验

实验窗口:


1.find /westos/ -perm -444       ---查找/westos/下所有权限包含444的文件(与的关系,三个条件,u包含4,g包含u,o包含u)


find /westos/ -perm -004       ---一个条件,ug忽略,o包含4的文件


find /westos/ -perm -644        ---4个条件


find /westos/ -perm -777        ---九个条件


2.find /westos/ -perm /444       ---查找权限包含444的文件(或的关系,u包含4或者g包含4或者o包含4)


find /westos/ -perm /777       ---查找但凡包含任意一个权限的文件


#find命令应用

 

find /mnt -perm -004 -exec chmod o-r {} \;   ---查找/mnt下所有other权限包含4的文件,将它们other的权限-r。{}代表着之前查找到的所有文件,分号;代表着命令结束

  • 7
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值