[命令] Linux 命令 at (延迟执行某个命令)

正文:

步骤一:安装 at 命令

# dnf install at

步骤二:启动 atd 进程

# systemctl enable --now atd

步骤三:通过 at 命令设置延迟执行命令

3.1 设置执行的时间并进入 at 模式

# 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 执行

3.2 设置执行的命令

at> reboot

(补充:这里以执行 reboot 命令为例)

3.3 退出 at 模式

at> <CtrlD> + <D>

at> <EOT>
job 5 at Tue Sep 16 22:37:00 2025
#

步骤四:查看 at 设置的要执行的命令

4.1 显示 at 所有设置的列表

# at -l
6	Tue Sep 16 22:37:00 2025 a root

4.2 显示某条 at 命令的设置

# at -c 6

(补充:这里以显示第 6 条 at 命令为例,这里的 6 是步骤 4.1 的输出结果)

补充:在脚本中使用 at 命令的方法

# vim test.sh

创建以下内容:

#!/bin/bash
at now + 1min << EOF

reboot

EOF

(补充:这里以创建名为 test.sh 在 1 分钟后重启系统为例)

[内容] Linux 命令 rmdir (删除目录)

案例一:使用 rmdir 命令删除目录

# rmdir -p test

(补充:这里以删除目录 test 为例)

案例二:使用 rmdir 命令删除目录和其子目录

# rmdir -p test1/test2/test3

或者:

# rmdir --parents test1/test2/test3

或者:

# rmdir --parents test1/test2/test3 test1/test2 test1

(补充:这里以删除目录 test1/test2/test3,test1/test2 和 test1 为例)

[命令] Linux 命令 shred (删除目录或文件)

正文:

内容一:shred 命令的作用

shred 的作用是删除文件。和 rm 命令不同的是 shred 在删除前会通过多次 (默认 3 次) 覆盖的方式防止数据被删除


注意:
1) 多次覆写大文件会消耗较多时间和 I/O 资源
2) 由于 SSD 的磨损均衡技术,shred 在 SSD 上可能无法完全擦除数据

内容二:shred 命令的格式

# shred <option> <file>

内容三:shred 命令的选项

1) -n <覆写的次数>,设置覆写的次数
2) -z ,最后用零进行覆写,以隐藏 shred 命令的痕迹
3) -u ,覆写后删除文件
4) -v ,显示详细过程
5) -f ,强制写入,若需要则修改权限
6) -x ,不处理超过文件大小的块

内容四:shred 命令的案例

4.1 以指定覆写次数的方式删除文件

# shred -n 5 -v test.txt

(补充:这里以覆写 5 次的方式删除 test.txt 文件为例)

4.2 以随机覆写次数的方式删除文件

# shred --random-source=/dev/urandom -v test.txt

(补充:这里以随机覆写次数的方式删除 test.txt 文件为例)

补充:

补充一:使用 dd 命令删除文件

# dd if=/dev/zero of=test.txt bs=1M count=10

(补充:这里以每次容量是 1M,覆写文件 test.txt 10 次为例)

补充二:使用 wipe 命令删除文件

# wipe -r -q test.txt

(补充:以清除 test.txt 文件为例)