Linux——find命令的使用


find命令查找文件目录

find 路径 查找方式

按文件名称查找 :

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

[root@node01 ~]# find /etc/ -name "*.conf" | wc -l

按文件大小查找:

[root@node01 ~]# find /etc/ -size +1M

[root@node01 ~]# find /etc/ -size +500k

按文件修改时间查找 :

[root@node01 ~]# find / -mtime +7 >>>7天前

[root@node01 ~]# find / -mtime -7 >>>7天内

按文件类型查找 :

1:文件的类型
[root@node01 ~]# ls -l
总用量 4
-rw-------. 1 root root 1722 7月 28 2016 anaconda-ks.cfg

-	文件 
d	目录 
l 	软链接文件(link)
b 	块设备文件(block), 硬盘、硬盘分区、U盘、光盘
c 	字符设备文件(character)		键盘、鼠标、显示器

[root@node01 ~]# find /dev/ -type b

[root@node01 ~]# find /dev/ -type l

复合条件:

1:查看7天内修改过的文件,且大于100k的
[root@node01 ~]# find / -mtime -7 -a -size +100k

-exec选项执行后续操作:

在这里插入图片描述

需求:在bj目录下找到.txt 的文件,找到后并且把它删了,其中exec是执行;(表示:对前面查出来的文件,执行什么样的操作)其中{}代表find命令查找出来的结果;;代表固定的结束符

需求:在bj目录下中找到.txt的文件,找到后把它复制到tmp目录下

find / -name "*.conf" |xargs gzip &

posted @ 2020-09-21 09:13  知秋一叶9527  阅读(196)  评论(0编辑  收藏  举报