find 使用及说明
find指令将从指定目录向下递归地遍历其各个子目录,将满足条件的文件或者目录显示在终端。
基本语法
find [搜索范围] [选项]
选项说明
选项 | 功能 |
---|---|
-name<查询方式> | 按照指定的文件名查找模式查找文件 |
-user<用户名> | 查找属于指定用户名所有文件 |
-size<文件大小> | 按照指定的文件大小查找文件 |
一、按文件名:根据名称查找/home目录下的a.txt文文件第二个参树是搜索的范围 -name 按照文件名 最后一个是文件
[root@localhost ~]# find /home/ -name a.txt
/home/a.txt
二、按拥有者:查找/home目录下,用户名称为root的文件
[root@localhost ~]# find /home/ -user root
/home/
/home/a.txt
三、查找整个linux系统下大于200m的文件(+n大于 -n小于 n等于)
[root@localhost ~]# find / -size +1M
/boot/efi/EFI/centos/MokManager.efi
/boot/efi/EFI/centos/mmx64.efi
/boot/efi/EFI/centos/shim.efi
/boot/efi/EFI/centos/shimx64-centos.efi
/boot/efi/EFI/centos/shimx64.efi
/boot/efi/EFI/BOOT/BOOTX64.EFI
/boot/grub2/fonts/unicode.pf2
......
四、查找/home目录下所有以.txt结尾的文件
[root@localhost ~]# find /home/ -name *.txt
/home/a.txt