2.23/2.24/2.25 find命令
find 搜索文件的命令
which ls:从环境变量 echo $PATH 中找的
whereis ls : 可以搜索,搜的不全
![](https://i-blog.csdnimg.cn/blog_migrate/76be18ff4bffa75af283ef71ae258abc.png)
安装: locate
[root@wangshuang-01 ~]# yum install -y mlocate
![](https://i-blog.csdnimg.cn/blog_migrate/c63a0682b144b4ef84174a59ab18944a.png)
模糊搜索:locate +关键字
![](https://i-blog.csdnimg.cn/blog_migrate/b3bef184f4b3803e98505e47b80ea5bb.png)
find /etc/ -name "sshd*"
根据文件的类型搜文件
搜目录
find /etc/ -type d -name "*.d"
![](https://i-blog.csdnimg.cn/blog_migrate/0b8da32b0909eacf1fc408965232fc69.png)
搜文件
find /etc/ -type f -name "sshd*"
搜软链接
find /etc/ -type l
搜socket文件
find /dev/ -type s
搜字符串文件
find /dev/ -type c
搜块设备
find /dev/ -type b
find / -type -name -mtime -ctime -atime
stat 查看文件的具体信息的,名字、大小、块、设备、权限、最近访问、更改时间等
Access:访问文件的时间,cat文件、more文件
Modify:修改文件
内容
Change:修改文件
权限,修改文件内容(大小、时间、权限、所有者、所属组)
修改文件权限,ctime会变,mtime不会变
更改文件的内容,ctime 一定会变,mtime也会变
访问文件. cat 1.txt ,atime 一定会变
查找在一天以内创建或修改的文件
[root@wangshuang-01 ~]# find / -type f -mtime -1
查找大于一天内创建或修改的文件
[root@wangshuang-01 ~]# find / -type f -mtime +1
查找一天以内在该路径下创建或修改的文件
[root@wangshuang-01 ~]# find /etc/ -type f -mtime -1
/etc/resolv.conf
/etc/group
/etc/gshadow
/etc/shadow
/etc/tuned/active_profile
[root@wangshuang-01 ~]# find /etc/ -type f -atime -1
[root@wangshuang-01 ~]# find /etc/ -type f -ctime -1
添加查找条件,-type,-ctime,-name 是并且的关系
[root@wangshuang-01 ~]# find /etc/ -type f -ctime -1 -name "*.conf"
/etc/resolv.conf
/etc/updatedb.conf
添加的查找条件,-ctime,-name 是或者的关系
[root@wangshuang-01 ~]# find /etc/ -type f -o -ctime -1 -o -name "*.conf"
根据inode号查找硬连接文件
查找60 分钟内创建的文件
[root@wangshuang-01 ~]# find /root/ -type f -mmin -60
/root/1.txt
查找60分钟内创建的文件,并且显示文件的详细信息
[root@wangshuang-01 ~]# find /root/ -type f -mmin -60 -exec ls -l {} \;
-rw-r--r--. 1 777 root 12 Jun 10 20:38 /root/1.txt
查找文件在200分钟内创建,且修改文件名称,在文件名称后加 .bak
![](https://i-blog.csdnimg.cn/blog_migrate/7b82afd4870c70ada4ce23f9bbb41978.png)
查找文件的大小,大于10k,小于10k
[root@wangshuang-01 ~]# find /root/ -type f -size +10k -exec ls -lh {} \;
[root@wangshuang-01 ~]# find /root/ -type f -size -10k -exec ls -lh {} \;
![](https://i-blog.csdnimg.cn/blog_migrate/3bda6af1c5531852b750f6f663c02547.png)
总结:find 常用命令,find -type ,-mtime , -mmin , -size , -o , -exec , -name
2.26 文件名后缀
在linux 下面可以自定义文件名及后缀,不能代表文件的类型,
修改语言:
![](https://i-blog.csdnimg.cn/blog_migrate/5fa39fa3b8410b0dd55d07d97d923a8e.png)