linux之find命令

find /etc/ -name passwd      ##查找/etc/下名称中带有passwd的文件
find /etc -maxdepth 1 -name passwd     ##查找/etc/下名称中带有passwd的文件,查找一层。
find /etc -name *.conf       ##查找/etc/下名称中带有*.conf的文件(下面显示的是部分)
find /etc -maxdepth 2 -name *.conf  ##查找/etc/下名称中带有*.conf的文件,且查找两层,包括一层(下面显示的是部分)
find /etc -maxdepth 2 -mindepth 2 -name *.conf  ##查找/etc/下名称中带有*.conf的文件,且只查找第二层
find /mnt -group tony             ##查找/mnt中所有组是tony用户的文件
find /mnt -user student -group student  ##查找/mnt中所有人和所有组都是student的文件
find /mnt -not -user student      ##查找/mnt中所有人不是student用户的文件
find /mnt -not -user student -o -group tony   ##查找/mnt中所有人不是student用户或者所有组是tony用户的文件
find /mnt -size 20K       ##查找/mnt文件大小近似20k的文件
find /mnt -size +20K      ##查找/mnt文件大小大于20k的文件
find /mnt -size -20K      ##查找/mnt文件大小小于20k的文件
find /mnt -type d         ##按type查找/mnt中目录
find /mnt -type f         ##按type查找/mnt中文件
find /mnt -cmin 10        ##查找/mnt中十分钟左右修改的
find /mnt -cmin +10       ##查找/mnt中十分钟以上修改的
find /mnt -cmin -10       ##查找/mnt中十分钟以内修改的
find /mnt -ctime 10       ##查找/mnt中十天左右修改的
find /mnt -ctime +10      ##查找/mnt中十天以上修改的
find /mnt -ctime -10      ##查找/mnt中十天以内修改的
find /mnt/ -perm 444      ##查找/mnt文件权限为444的文件
find /mnt/ -perm -444     ##查找/mnt中user有读的权限且group有读的权限且other有读的权限的文件。(三个条件,u.g.o至少要读的权限即r--r--r--)
find /mnt/ -perm -004     ##查找/mnt中other有读权限的文件(一个条件,o至少有读的权限)
find /mnt/ -perm -644     ##查找/mnt中user有读写的权限且group至少有读权限且other有读的权限的文件。(四个条件,rw-r--r--)
find /etc/ -name *.conf -exec cp -rp {} /mnt \;   ##把/etc/目录下名称中带有.conf的文件递归复制到/mnt下
find /mnt -name "*.conf" -exec rm -fr {} \; ##删除/mnt名称中带有.conf的文件
find / -group mail -exec cp -rp {} /mnt \; ##把/目录下的组属于mail的文件复制到/mnt
find /etc/ -name passwd      ##查找/etc/下名称中带有passwd的文件


 

find /etc -maxdepth 1 -name passwd     ##查找/etc/下名称中带有passwd的文件,查找一层。

find /etc -name *.conf       ##查找/etc/下名称中带有*.conf的文件(下面显示的是部分)


 

find /etc -maxdepth 2 -name *.conf  ##查找/etc/下名称中带有*.conf的文件,且查找两层,包括一层(下面显示的是部分)


 

find /etc -maxdepth 2 -mindepth 2 -name *.conf  ##查找/etc/下名称中带有*.conf的文件,且只查找第二层

举例:
useradd tony
cd /mnt touch file{1..5} ##建立五个file文件
chown student.student /mnt/file1 ##改变file1所有人和所有组都为student
chown root.student /mnt/file2 ##改变file2的所有组为student
chown tony.student /mnt/file3 ##改变file3所有人为tony,所有组为student
chown root tony /mnt/file4 ##改变file4所有组为tony


 

监控命令: watch -n 1 ls -lR /mnt

find /mnt -group tony             ##查找/mnt中所有组是tony用户的文件


 

find /mnt -user student -group student  ##查找/mnt中所有人和所有组都是student的文件

find /mnt -not -user student -o -group tony   ##查找/mnt中所有人不是student用户或者所有组是tony用户的文件


 

find /mnt -not -user student      ##查找/mnt中所有人不是student用户的文件


 

find /mnt -not -user student -o -group tony   ##查找/mnt中所有人不是student用户或者所有组是tony用户的文件

举例:
cd /mnt
rm -fr *
dd if=/dev/zero of=file1 bs=1 count=10240
dd if=/dev/zero of=file2 bs=1 count=20480
dd if=/dev/zero of=file3 bs=1 count=40960

find /mnt -size 20k      ##查找/mnt文件大小近似20k的文件


 

find /mnt -size +20k      ##查找/mnt文件大小大于20k的文件


 

find /mnt -size -20k      ##查找/mnt文件大小小于20k的文件

find /mnt -type d         ##按type查找/mnt中目录

find /mnt -type f         ##按type查找/mnt中文件

find /mnt -cmin 10        ##查找/mnt中十分钟左右修改的
find /mnt -cmin +10       ##查找/mnt中十分钟以上修改的
find /mnt -cmin -10       ##查找/mnt中十分钟以内修改的

find /mnt -ctime 10       ##查找/mnt中十天左右修改的
find /mnt -ctime +10      ##查找/mnt中十天以上修改的
find /mnt -ctime -10      ##查找/mnt中十天以内修改的

举例:
cd /mnt
rm -rf *
mkdir file{1..5}
ls
chmod 000 * ##修改所有file文件的权限为000
chmod 404 file1 ##修改file1文件的权限为404
chmod 444 file2 ##修改file2文件的权限为444
chmod 644 file3 ##修改file3文件的权限为644
chmod 640 file4 ##修改file4文件的权限为640

find /mnt/ -perm 444      ##查找/mnt文件权限为444的文件

find /mnt/ -perm -444     ##查找/mnt中user有读的权限且group有读的权限且other有读的权限的文件。(三个条件,u.g.o至少要读的权限即r--r--r--)


 

find /mnt/ -perm -004     ##查找/mnt中other有读权限的文件(一个条件,o至少有读的权限)

find /mnt/ -perm -644     ##查找/mnt中user有读写的权限且group至少有读权限且other有读的权限的文件。(四个条件,rw-r--r--)

删除/mnt中文件的other的读权限:
方法1
chmod o-r $(find /mnt -perm -004)
方法2
find /mnt -perm -004 -exec chmod o-r {} \;

find /etc/ -name *.conf -exec cp -rp {} /mnt \;   ##把/etc/目录下名称中带有.conf的文件递归复制到/mnt下


 

find /mnt -name "*.conf" -exec rm -fr {} \; ##删除/mnt名称中带有.conf的文件


 

find / -group mail -exec cp -rp {} /mnt \; ##把/目录下的组属于mail的文件复制到/mnt

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值