Linux中find命令介绍

1.寻找/etc下有xxx的文件

<1>查找/etc下名字中有password的目录或文件

[root@station ~]# find /etc/ -name password

在这里插入图片描述
<2>查找/etc下名字中是以.conf结尾的所有目录或文件

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

在这里插入图片描述

2.关于文件所属用户或用户组的查找

<1>前提:查看/mnt下文件的权限及属性

[root@station ~]# ll  /mnt/*

在这里插入图片描述
<2>查找/mnt下所属用户是root的目录或文件

[root@station ~]# find /mnt/ -user root

在这里插入图片描述
<3>查找/mnt下所属组是westos的目录或文件

[root@station ~]# find /mnt/ -group westos

在这里插入图片描述
<4>查看/mnt下所属用户和所属组都是westos的文件

[root@station ~]# find /mnt/ -group westos -user westos

在这里插入图片描述
<5>查看/mnt下所属用户或所属组是westos的文件

[root@station ~]# find /mnt/ -group westos -o -user westos

在这里插入图片描述
注意:-o表示或者,不加默认为并且

3.关于某层目录的查找

<1>查找/etc目录中第一层目录中以.conf结尾的文件

[root@station ~]# find /etc -maxdepth 1 -name "*.conf"

在这里插入图片描述
<2>查找/etc目录的子目录里最大的两层或者最小的两层中以.conf结尾的文件(本身etc就是一层)

[root@station ~]# find /etc -maxdepth 2 -mindepth 2 -name "*.conf"	

在这里插入图片描述

4.关于文件容量大小及修改,访问时间的查找

<1>

find /etc -size 20K	##查找/etc目录下文件容量为20k文件
find /etc -size -20K	##查找/etc目录下文件容量在20k以内的文件
find /etc -size +20K	##查找/etc目录下文件容量在20k以外的文件

举例:

  -1-  [root@station ~]# find /etc -size 20k

在这里插入图片描述

   -2- [root@station ~]# find /etc -size -20k

在这里插入图片描述
在这里插入图片描述

-3-  [root@station ~]# find /etc -size +20k

在这里插入图片描述
在这里插入图片描述
<2>

find /etc -ctime 4	##查找/etc目录下文件修改时间为4天的文件
find /etc -ctime -4	##查找/etc目录下文件修改时间小于4天的文件
find /etc -ctime +4	##查找/etc目录下文件修改时间大于4天的文件
find /etc -atime 4	##查找/etc目录下文件访问时间为4天的文件
find /etc -atime -4	##查找/etc目录下文件访问时间小于4天的文件
find /etc -atime +4	##查找/etc目录下文件访问时间大于4天的文件

举例:
-1-[root@station ~]# find /etc -ctime 4
在这里插入图片描述
-2-[root@station ~]# find /etc -ctime -4
在这里插入图片描述
-3-[root@station ~]# find /etc -ctime +4
在这里插入图片描述

-4-[root@station ~]# find /etc -atime 4

在这里插入图片描述
-5-[root@station ~]# find /etc -atime -4
在这里插入图片描述

-6-[root@station ~]# find /etc -atime +4

在这里插入图片描述

5.关于find查找后处理查找文件

<1>查找/mnt目录下文件名是以.conf结尾的所有文件并将其删除

find /mnt/ -name "*.conf" -exec rm -rf {} \;	
[root@station ~]# ls /mnt
[root@station ~]# find /mnt/ -name "*.conf" -exec rm -rf {} \;
[root@station ~]# ls /mnt

在这里插入图片描述
分析:用“ ”表示文件中应该含有的内容,用-exec表示要对找出的文件进行的操作,用{}表示找出的文件,用\表示操作完毕
<2>查找/mnt目录下文件名是以.conf结尾的所有文件,并将其都复制到/mnt目录下

[root@station ~]# ls /mnt
[root@station ~]# find /mnt/ -name "*.conf" -exec cp -rp {} /westos \;
[root@station ~]# ls /westos

在这里插入图片描述
注意:cp -rp指复制目录且保留属性(-r 复制目录,-p 保留文件属性)

(你可以帮我洗个东西吗?喜欢我)

猜你喜欢

转载自blog.csdn.net/qq_39376481/article/details/87101840