案例一:显示 /etc/passwd 文件里的信息
# getent passwd root
(补充:这里以显示 /etc/passwd 文件里的 root 信息为例)
案例二:显示 /etc/hosts 文件里的信息
# getent host 127.0.0.1
(补充:这里以显示 /etc/hosts 文件里的 127.0.0.1 信息为例)
# getent passwd root
(补充:这里以显示 /etc/passwd 文件里的 root 信息为例)
# getent host 127.0.0.1
(补充:这里以显示 /etc/hosts 文件里的 127.0.0.1 信息为例)
# dirname -- "$( readlink -f -- "$0"; )";
# dnf install at
# systemctl enable --now atd
# at now +3 minutes
warning: commands will be executed using /bin/sh
(
补充:这里的 now +3 minutes 代表当前时间 3 分钟后执行。
所有可选的时间选项如下:
1) now +3 minutes,3 分钟后执行
2) now +3 hours,3 小时后执行
3) now +3 days,3 天后执行
4) 15:30,当天 15:30 时执行
5) 15:30 2025-01-01,2025 年 1 月 1 日时执行
6) teatime,当天 16:00 执行
7) midnight 次日凌晨 00:00 执行
)
at> reboot
(补充:这里以执行 reboot 命令为例)
at> <CtrlD> + <D>
at> <EOT>
job 5 at Tue Sep 16 22:37:00 2025
#
# at -l
6 Tue Sep 16 22:37:00 2025 a root
# at -c 6
(补充:这里以显示第 6 条 at 命令为例,这里的 6 是步骤 4.1 的输出结果)
# vim test.sh
创建以下内容:
#!/bin/bash
at now + 1min << EOF
reboot
EOF
(补充:这里以创建名为 test.sh 在 1 分钟后重启系统为例)
# rmdir -p test
(补充:这里以删除目录 test 为例)
# rmdir -p test1/test2/test3
或者:
# rmdir --parents test1/test2/test3
或者:
# rmdir --parents test1/test2/test3 test1/test2 test1
(补充:这里以删除目录 test1/test2/test3,test1/test2 和 test1 为例)
shred 的作用是删除文件。和 rm 命令不同的是 shred 在删除前会通过多次 (默认 3 次) 覆盖的方式防止数据被删除
(
注意:
1) 多次覆写大文件会消耗较多时间和 I/O 资源
2) 由于 SSD 的磨损均衡技术,shred 在 SSD 上可能无法完全擦除数据
)
# shred <option> <file>
1) -n <覆写的次数>,设置覆写的次数
2) -z ,最后用零进行覆写,以隐藏 shred 命令的痕迹
3) -u ,覆写后删除文件
4) -v ,显示详细过程
5) -f ,强制写入,若需要则修改权限
6) -x ,不处理超过文件大小的块
# shred -n 5 -v test.txt
(补充:这里以覆写 5 次的方式删除 test.txt 文件为例)
# shred --random-source=/dev/urandom -v test.txt
(补充:这里以随机覆写次数的方式删除 test.txt 文件为例)
# dd if=/dev/zero of=test.txt bs=1M count=10
(补充:这里以每次容量是 1M,覆写文件 test.txt 10 次为例)
# wipe -r -q test.txt
(补充:以清除 test.txt 文件为例)