文章目录
一、Linux下文件查找命令
1、命令查找
注意:Linux下一切皆文件
which 命令:找出命令的绝对路径
whereis 命令:找出命令的路径以及文档手册信息
[root@rh ~]# which cd
/usr/bin/cd
[root@rh ~]# whereis cd
cd: /usr/bin/cd /usr/share/man/man1/cd.1.gz /usr/share/man/man1p/cd.1p.gz
2、文件查找(find)
find命令:精确查找,磁盘搜索,IO读写,CPU开销大
用法1:找出来输出到屏幕
根据需求查找出来直接输出到屏幕
find 查找路径 选项 关键字
常见选项 | ||
---|---|---|
-name | 按照文件名查找文件 | |
-iname | 按照文件名忽略大小写查找 | |
-size | 按照文件大小来查找 | +1M 大于1M -1M 小于1M 1M 等于1M |
-type | 按照文件类型来查找 | |
-mtime | 按文件修改时间来查找文件 | -n指n天以内,+n指n天以前 |
-atime | 按文件访问时间来查 | |
-ctime | 按文件创建时间来查找文件 | |
-perm | 按照文件权限来查找文件 |
举例说明:
1)根据文件名查找
[root@heima ~]# find /test -name "file1"
[root@heima ~]# find /test -iname "file1"
[root@heima ~]# find /etc -name "*.conf"
2)根据文件类型查找
[root@heima ~]# find /usr/bin/ -type l
[root@heima ~]# find /dev -type b
[root@heima ~]# cd /test
[root@heima test]# find . -type d
[root@heima test]# find . -type f
3)根据文件大小查找
[root@heima test]# find . -type f -size +1M
[root@heima test]# find . -type f -size -1M
[root@heima test