[内容] /etc/resolv.conf 配置文件的 search 选项

内容一:测试 search 选项的配置

# cat /etc/resolv.conf
search eternalcenter.com local new
nameserver 8.8.8.8

内容二:测试 search 选项

2.1 查询 zhumingyu

# host -a zhumingyu
Trying "zhumingyu.eternalcenter.com"
Trying "zhumingyu.local"
Trying "zhumingyu.new"
Trying "zhumingyu"
Host zhumingyu not found: 3(NXDOMAIN)
Received 102 bytes from 8.8.8.8#53 in 62 ms

(补充:当查询 zhumingyu 时,也就是中间没有点 “.”,则默认会被视为查询主机名,会先依次把 eternalcenter.com、local 和 new 作为后缀添加到 zhumingyu 后进行查询,最后才查询 zhumingyu)

2.2 zhumingyu.com

# host -a zhumingyu.com
Trying "zhumingyu.com"
Received 31 bytes from 1.1.1.1#53 in 217 ms
Trying "zhumingyu.com.eternalcenter.com"
Trying "zhumingyu.com.local"
Trying "zhumingyu.com.new"
Host zhumingyu.com.new not found: 4(NOTIMP)
Received 35 bytes from 1.1.1.1#53 in 218 ms

(补充:当查询 zhumingyu.com 时,也就是中间有 1 个点 “.”,则默认会被视为查询域名,会先查询 mingyuzhu.com,如果查询失败,则会先依次把 eternalcenter.com、local 和 new 作为后缀添加到 zhumingyu 后进行查询)

2.3 查询 zhumingyu.com.

# host -a zhumingyu.com.
Trying "zhumingyu.com"
Host zhumingyu.com not found: 4(NOTIMP)
Received 31 bytes from 1.1.1.1#53 in 204 ms
Received 31 bytes from 1.1.1.1#53 in 204 ms

(补充:当查询 zhumingyu.com. 时,也就是末尾有 1 个点 “.”,默认会被视为查询域名,且只会查询这个域名。不会查询 search 里的每 1 项)

[命令] Linux 命令 locate (查找文件)

内容一:locate 命令的安装

1.1 安装 locate 命令

# dnf install mlocate

1.2 更新 locate 数据库

# updatedb


注意:如果不更新 locate 数据库,在使用 locate 命令后可能会报错

locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory

内容二:locate 命令的选项

1) -b 或者 –basename 只显示使用指定模式匹配名称的条目
2) -c 或者 –count 只显示找的数量
3) -e 或者 –existing 只显示存在的条目
4) -i 或者 –ignore-case 查找时忽略大小写
5) -r 或者 –regexp 使用正则表达式
6) –regex 使用扩展正则表达式

内容三:locate 命令的案例

3.1 案例一:查找包含 passwd 的文件

# locate passwd

3.2 案例二:在 /etc/ 目录下查找以 sh 开头的文件

# locate /etc/sh

3.3 案例三:在当前目录下查找以 r 开头的文件并忽略大小写

# locate -i ~/r

3.4 案例四:使用正则表达式超找包含 1.txt 或 2.txt 的文件

# locate -r [1-2].txt