From ef69ba4b0fe1792a3e29d82d8cc2545da5360d88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=AC=A3?= <12078128+rainbow-meet-rose-die@user.noreply.gitee.com> Date: Wed, 19 Jun 2024 14:29:08 +0000 Subject: [PATCH] =?UTF-8?q?=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李欣 <12078128+rainbow-meet-rose-die@user.noreply.gitee.com> --- ...57\345\242\203\345\217\230\351\207\217.md" | 335 ++++++++++++++++++ 1 file changed, 335 insertions(+) create mode 100644 "51 \346\235\216\346\254\243/20240618\345\221\250\346\234\237\344\273\273\345\212\241\344\270\216\347\216\257\345\242\203\345\217\230\351\207\217.md" diff --git "a/51 \346\235\216\346\254\243/20240618\345\221\250\346\234\237\344\273\273\345\212\241\344\270\216\347\216\257\345\242\203\345\217\230\351\207\217.md" "b/51 \346\235\216\346\254\243/20240618\345\221\250\346\234\237\344\273\273\345\212\241\344\270\216\347\216\257\345\242\203\345\217\230\351\207\217.md" new file mode 100644 index 0000000..0309567 --- /dev/null +++ "b/51 \346\235\216\346\254\243/20240618\345\221\250\346\234\237\344\273\273\345\212\241\344\270\216\347\216\257\345\242\203\345\217\230\351\207\217.md" @@ -0,0 +1,335 @@ +### 周期任务 + +#### cron 基于时间的任务调度程序 + +##### ‘*’ 范围内每一个 + +##### ‘-’ N到N+1的范围 + +##### / 间隔 + +##### , 列出所有指定值 + +##### ? 位意一个 + +##### L(Last) 表示最后一个,可以在月的天数或星期几中使用 + +##### W 工作日,若那天不是工作日,选择最近的工作日,但不跨月 + +##### crontab -l 查看计划位务 + +##### crontab -e 编辑 + +##### crontab -r 删除 + +/var/spool/cron/crontabs 用户级 +/etc/crontab 分身 /etc/cron.d/ 系统级 + +##### 分五个刻度 + + 分0-59 时0-23 天1-31 月1-12 周:0-7 + +### 环境变量 + +```bash +#打印所有环境变量 +printenv +env +#设置临时环境变量 +export MY_VAR="值" +echo $MY_VAR +#设置语言和地区 +export LANG=en_US.UTF-8 +export LC_ALL=en_US.UTF-8 +#设置路径变量 +export PATH=$PATH:路径 +#自定义别名 +alias ll='ls -la' +#永久变量可在用户级或系统级文件写 +~/.bashrc ~/profile 用户级 用于不同用户 +/etc/environment /etc/profile 系统级 为所有用户和系统服务提供 +``` + + + +### 周期任务练习 + +执行在家目录touch a.txt + +1. 每天3:00执行一次 + + ```bash + 0 3 * * * touch a.txt /home/lmd/ + ``` + + + +2. 每周六2:00执行 + + ```bash + 0 2 * * 6 touch a.txt /home/lmd/ + ``` + + + +3. 每周六1:05执行 + + ```bash + 5 1 * * 6 touch a.txt /home/lmd/ + ``` + + + +4. 每周六1:25执行 + + ```bash + 25 1 * * 6 touch a.txt /home/lmd/ + ``` + + + +5. 每天8:40执行 + + ```bash + 40 8 * * * touch a.txt /home/lmd/ + ``` + + + +6. 每天3:50执行 + + ```bash + 50 3 * * * touch a.txt /home/lmd/ + ``` + + + +7. 每周一到周五的3:40执行 + + ```bash + 40 3 * * 1-5 touch a.txt /home/lmd/ + ``` + + + +8. 每周一到周五的3:41开始,每10分钟执行一次 + + ```bash + 41/10 3 * * 1-5 touch a.txt /home/lmd/ + ``` + + + +9. 每天的10:31开始,每2小时执行一次 + + ```bash + 50 3 * * * touch a.txt /home/lmd/ + ``` + + + +10. 每周一到周三的9:30执行一次 + + ```bash + 30 9 * * 1-3 touch a.txt /home/lmd/ + ``` + + + +11. 每周一到周五的8:00,每周一到周五的9:00执行一次 + + ```bash + 0 8-9 * * 1-5 touch a.txt /home/lmd/ + ``` + + + +12. 每天的23:45分执行一次 + + ```bash + 45 23 * * * touch a.txt /home/lmd/ + ``` + + + +13. 每周三的23:45分执行一次 + + ```bash + 45 23 * * 3 touch a.txt /home/lmd/ + ``` + + + +14. 每周一到周五的9:25到11:35、13:00到15:00之间,每隔10分钟执行一次 + + ```bash + 25-59/10 9 * * 3 touch a.txt /home/lmd/ + */10 10 * * 3 touch a.txt /home/lmd/ + 0-35/10 11 * * 3 touch a.txt /home/lmd/ + 0/10 13-15 * * 3 touch a.txt /home/lmd/ + ``` + + + +15. 每周一到周五的8:30、8:50、9:30、10:00、10:30、11:00、11:30、13:30、14:00、14:30、5:00分别执行一次 + + ```bash + 30 8-11,13,14 * * 1-5 touch a.txt /home/lmd/ + 50 8 * * 1-5 touch a.txt /home/lmd/ + 0 10,11,14 * * 1-5 touch a.txt /home/lmd/ + ``` + + + +16. 每天16:00、10:00执行一次 + + ```bash + 0 16,10 * * * touch a.txt /home/lmd/ + ``` + + + +17. 每天8:10、16:00、21:00分别执行一次 + + ```bash + 0 8,16,21 * * * touch a.txt /home/lmd/ + ``` + + + +18. 每天7:47、8:00分别执行一次 + + ```bash + 0 8 * * * touch a.txt /home/lmd/ + 47 7 * * * touch a.txt /home/lmd/ + ``` + + + + ### 练习题 1: 显示当前所有的环境变量 + + * 使用`printenv`或`env`命令来显示所有的环境变量。 + + + ```bash + lmd@hecs-288852:~$ env + lmd@hecs-288852:~$ printenv + ``` + + ### 练习题 2: 显示`HOME`环境变量的值 + + * 使用`echo`命令和`$`符号来显示`HOME`环境变量的值。 + + + ```bash + lmd@hecs-288852:~$ echo $HOME + /home/lmd + ``` + + ### 练习题 3: 临时设置一个新的环境变量 + + * 设置一个名为`MY_AGE`的环境变量,并将其值设置为`18`。 + + + ```bash + lmd@hecs-288852:~$ export MY_AGE=18 + ``` + + ### 练习题 4: 显示新设置的环境变量 + + * 使用`echo`命令来显示`MY_AGE`的值。 + + + ```bash + lmd@hecs-288852:~$ echo $MY_AGE + 18 + ``` + + ### 练习题 5: 在新的shell会话中检查环境变量 + + * 打开一个新的终端窗口或标签页,并尝试显示`MY_AGE`的值。你会看到什么?为什么? + + 没有值,因为只是临时变量 + + ### 练习题 6: 修改`PATH`环境变量 + + * 将`你当前用户的家目录`添加到你的`PATH`环境变量的末尾位置 + + + ```bash + lmd@hecs-288852:~$ PATH=$PATH:/home/lmd + ``` + + 将`/tmp`添加到你的`PATH`环境变量的开始位置,(注意:这可能会覆盖其他路径中的同名命令,所以请谨慎操作)。 + + ``` + lmd@hecs-288852:~$ export PATH=/tmp:$PATH + lmd@hecs-288852:~$ echo $PATH + /tmp:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/lmd + ``` + + ### 练习题 7: 验证`PATH`的修改 + + * 使用`echo`命令显示`PATH`的值,并确认`前面添加的目录`已经被添加到对应位置。 + + + ```bash + lmd@hecs-288852:~$ echo $PATH + /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/lmd + ``` + + ### 练习题 8: 永久设置环境变量 + + * 在你的shell配置文件中(如`~/.bashrc`、`~/.bash_profile`、`~/.zshrc`等,取决于你使用的shell和配置)添加一行来永久设置`MY_NAME`,值设置为`奥德彪`。 + + 例如,对于bash shell,你可以使用: + + + ```bash + lmd@hecs-288852:~$ vim .bashrc + 在末尾添加 export MY_NAME="奥德彪" + ``` + + 如何让`MY_NAME`生效,并验证 + + ``` + lmd@hecs-288852:~$ source ~/.bashrc + lmd@hecs-288852:~$ echo $MY_NAME + 奥德彪 + ``` + + ### 练习题 9: 清理 + + * 清除你之前设置的`MY_AGE`和`PATH`的修改(如果你不想永久保留它们)。 + + + ```bash + lmd@hecs-288852:~$ unset MY_AGE + ``` + + ### 练习题 10: 修改默认器 + + * 使用`EDITOR`变量,修改你默认的编辑器为nano。 + + + ```bash + export EDITOR=/usr/bin/naono + ``` + + ### 练习题 11: 修改语言 + + * 使用`LANG`变量,让你的文件支持中文和utf8编码来避免乱码。 + + ``` + lmd@hecs-288852:~$ export LANG=zh_CN.utf8 + ``` + + - 使用`LANGUAGE`变量,让你的命令提示为中文 + + ``` + lmd@hecs-288852:~$ export LANGUAGE=zh_CN.utf8 + lmd@hecs-288852:~$ dsff + -bash: dsff:未找到命令 + ``` + + \ No newline at end of file -- Gitee