From bb1bc31504ce999e235f228a5b2316f54a25374b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=80=9D=E5=A9=B7?= <3377421251@qq.com> Date: Mon, 17 Jun 2024 21:12:51 +0800 Subject: [PATCH] 2024.06.15 --- ...07\344\273\266\347\256\241\347\220\206.md" | 22 ++- ...03\351\231\220\347\256\241\347\220\206.md" | 3 +- ...73\345\212\241\347\256\241\347\220\206.md" | 150 ++++++++++++++++++ 3 files changed, 168 insertions(+), 7 deletions(-) create mode 100644 "44 \351\231\206\346\200\235\345\251\267/2024.06.15-\350\256\241\345\210\222\344\273\273\345\212\241\347\256\241\347\220\206.md" diff --git "a/44 \351\231\206\346\200\235\345\251\267/2024.05.21-Linux\346\226\207\344\273\266\345\244\271\345\217\212\346\226\207\344\273\266\347\256\241\347\220\206.md" "b/44 \351\231\206\346\200\235\345\251\267/2024.05.21-Linux\346\226\207\344\273\266\345\244\271\345\217\212\346\226\207\344\273\266\347\256\241\347\220\206.md" index a66eade..8bc5c39 100644 --- "a/44 \351\231\206\346\200\235\345\251\267/2024.05.21-Linux\346\226\207\344\273\266\345\244\271\345\217\212\346\226\207\344\273\266\347\256\241\347\220\206.md" +++ "b/44 \351\231\206\346\200\235\345\251\267/2024.05.21-Linux\346\226\207\344\273\266\345\244\271\345\217\212\346\226\207\344\273\266\347\256\241\347\220\206.md" @@ -154,20 +154,30 @@ ## touch - +**touch:用于创建新文件和更新文件时间戳** + +1. **创建一个空文件** + - touch filename + - 如果 filename 不存在,touch 会创建一个新的空文件。 +2. **更新文件的时间戳** + - touch filename + - 如果 filename 已经存在,touch 会更新该文件的访问和修改时间为当前时间。 + #只更新时间,不更新内容 +3. **创建多个空文件** + - touch file1 file2 file3 + - touch 可以同时创建多个空文件 ——————————————————————————— ## rm -**rm:删除文件或目录** - -**rmdir:删除空目录** - -`rm -rf a.txt rm -rf cl`:删除文件a.txt或目录cl +- **rm:删除文件或目录** + - `rm -rf a.txt rm -rf cl`:删除文件a.txt或目录cl +- **rmdir:删除空目录** | 选项 | 作用 | | ----- | ---------------------------- | +| `-i` | 删除前会询问是否删除 | | `-r` | 递归删除目录及其内全部子文件 | | `-f ` | 强制删除文件而不询问 | | | | diff --git "a/44 \351\231\206\346\200\235\345\251\267/2024.06.14-\347\224\250\346\210\267\347\256\241\347\220\206\345\222\214\346\235\203\351\231\220\347\256\241\347\220\206.md" "b/44 \351\231\206\346\200\235\345\251\267/2024.06.14-\347\224\250\346\210\267\347\256\241\347\220\206\345\222\214\346\235\203\351\231\220\347\256\241\347\220\206.md" index def08b9..d11f3fb 100644 --- "a/44 \351\231\206\346\200\235\345\251\267/2024.06.14-\347\224\250\346\210\267\347\256\241\347\220\206\345\222\214\346\235\203\351\231\220\347\256\241\347\220\206.md" +++ "b/44 \351\231\206\346\200\235\345\251\267/2024.06.14-\347\224\250\346\210\267\347\256\241\347\220\206\345\222\214\346\235\203\351\231\220\347\256\241\347\220\206.md" @@ -350,9 +350,10 @@ 20. 通过id groups等命令查看用户handy信息 ```bash + `id` lsting@lst:~/06.14/guanli$ id handy uid=1008(handy) gid=1008(handy) groups=1008(handy),2003(jishu),2000(guanli) - + `group` lsting@lst:~/06.14/guanli$ groups handy handy : handy jishu guanli ``` \ No newline at end of file diff --git "a/44 \351\231\206\346\200\235\345\251\267/2024.06.15-\350\256\241\345\210\222\344\273\273\345\212\241\347\256\241\347\220\206.md" "b/44 \351\231\206\346\200\235\345\251\267/2024.06.15-\350\256\241\345\210\222\344\273\273\345\212\241\347\256\241\347\220\206.md" new file mode 100644 index 0000000..4cdb6f2 --- /dev/null +++ "b/44 \351\231\206\346\200\235\345\251\267/2024.06.15-\350\256\241\345\210\222\344\273\273\345\212\241\347\256\241\347\220\206.md" @@ -0,0 +1,150 @@ +## 计划任务管理 + +### 概括 + +- 可以Linux在无须人为介入的情况下,在指定的时间段自动启用或停止某些服务或命令 + +### 命令 `crontab` + +- **参数及作用** + + | 参数 | 作用 | + | ---- | ------------------------ | + | `-e` | 编辑计划任务(crontab -e) | + | `-u` | 指定用户名称(crontab -u) | + | `-l` | 列出任务列表(crontab -l) | + | `-r` | 删除计划任务(crontab -r) | + +- **设置任务的参数格式** + + ```bash + ` 分钟 小时 日期 月份 星期 命令 + # 字段没有被设置,则需要使用星号(*)占位 + ,:用逗号来分别表示多个时间段 + -:表示一段连续的时间周期 + /:表示执行任务的间隔时间 + ``` + +## 练习 + +### 周期任务练习 + +执行在家目录touch a.txt + +1. 每天3:00执行一次 + + ```bash + 0 3 * * * touch a.txt + ``` + +2. 每周六2:00执行 + + ```bash + 0 2 6 * * touch a.txt + ``` + +3. 每周六1:05执行 + + ```bash + 5 1 6 * * touch a.txt + ``` + +4. 每周六1:25执行 + + ```bash + 25 1 6 * * touch a.txt + ``` + +5. 每天8:40执行 + + ```bash + 40 8 * * * touch a.txt + ``` + +6. 每天3:50执行 + + ```bash + 50 3 * * * touch a.txt + ``` + +7. 每周一到周五的3:40执行 + + ```bash + 40 3 * * 1-5 touch a.txt + ``` + +8. 每周一到周五的3:41开始,每10分钟执行一次 + + ```bash + 41/10 3 * * 1-5 touch a.txt + ``` + +9. 每天的10:31开始,每2小时执行一次 + + ```bash + 31 10/2 * * * touch a.txt + ``` + +10. 每周一到周三的9:30执行一次 + + ```bash + 30 9 * * 1-3 touch a.txt + ``` + +11. 每周一到周五的8:00,每周一到周五的9:00执行一次 + + ```bash + 0 8,9 * * 1-5 touch a.txt + ``` + +12. 每天的23:45分执行一次 + + ```bash + 45 23 * * * touch a.txt + ``` + +13. 每周三的23:45分执行一次 + + ```bash + 45 23 * * 3 touch a.txt + ``` + +14. 每周一到周五的9:25到11:35、13:00到15:00之间,每隔10分钟执行一次 + + ```bash + 25-35/10 9 * * 1-5 touch a.txt + 0-55/10 10-11 * * 1-5 touch a.txt + 00/10 13-15 * * 1-5 touch a.txt + ``` + +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,50 8 * * 1-5 touch a.txt + 30 9 * * 1-5 touch a.txt + 00,30 10 * * 1-5 touch a.txt + 00,30 11 * * 1-5 touch a.txt + 30 13 * * 1-5 touch a.txt + 00,30 * * 1-5 touch a.txt + 00 5 * * 1-5 touch a.txt + ``` + +16. 每天16:00、10:00执行一次 + + ```bash + 00 10,16 * * * touch a.txt + ``` + +17. 每天8:10、16:00、21:00分别执行一次 + + ```bash + 10 8 * * * touch a.txt + 00 16,21 * * * touch a.txt + ``` + +18. 每天7:47、8:00分别执行一次 + + ```bash + 47 7 * * * touch a.txt + 00 8 * * * touch a.txt + ``` -- Gitee