find #查找和搜索文件
选项:
-type #根据文件类型进行查找
f #普通文件
d #目录
l #软连接文件
s #socket文件 套接字文件
p #管道文件
-name #根据名称进行查找
-iname #查找的时候忽略大小写
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
#在/etc目录下进行查找 查找类型为普通文件 名称为 hostname 精确查找 [root@clf ~]# find /etc -type f -name "hostname" /etc/hostname [root@clf ~]# touch /opt/hostname{,ctl} [root@clf ~]# ll /opt/ total 0 -rw-r--r--. 1 root root 0 Jul 10 10:32 hostname -rw-r--r--. 1 root root 0 Jul 10 10:32 hostnamectl [root@clf ~]# touch /opt/test_hostname [root@clf ~]# touch /opt/test_hostname.txt [root@clf ~]# ll /opt/ total 0 -rw-r--r--. 1 root root 0 Jul 10 10:32 hostname -rw-r--r--. 1 root root 0 Jul 10 10:32 hostnamectl -rw-r--r--. 1 root root 0 Jul 10 10:32 test_hostname -rw-r--r--. 1 root root 0 Jul 10 10:33 test_hostname.txt [root@clf ~]# find /opt/ -type f -name "hostname" /opt/hostname #查找以hostname开头的文件 [root@clf ~]# find /opt/ -name "hostname*" /opt/hostname /opt/hostnamectl #查找以hostname为结尾的文件 [root@clf ~]# find /opt/ -name "*hostname" /opt/hostname /opt/test_hostname #查找文件名称包含hostname的文件 [root@clf ~]# find /opt/ -name "*hostname*" /opt/hostname /opt/hostnamectl /opt/test_hostname /opt/test_hostname.txt #查找所有文件,包括隐藏文件 [root@clf ~]# touch /opt/.hostname.log [root@clf ~]# find /opt/ -name "*hostname*" /opt/hostname /opt/hostnamectl /opt/test_hostname /opt/test_hostname.txt /opt/.hostname.log [root@clf ~]# find /opt/ -type d -iname "*hostname*" /opt/HOSTNAMECTL |