From 1683f9f35599076bd09b24f0bfded40938d6e8f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E8=8B=A5=E6=98=95?= <2175179136@qq.com> Date: Mon, 27 May 2024 20:07:31 +0800 Subject: [PATCH 1/2] 30 grx --- ...73\345\212\250\345\244\215\345\210\266.md" | 1 + ...35\345\257\271\350\267\257\345\276\204.md" | 184 ++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 "29 \351\203\255\350\213\245\346\230\225/20240527 \347\233\270\345\257\271\350\267\257\345\276\204\345\222\214\347\273\235\345\257\271\350\267\257\345\276\204.md" diff --git "a/29 \351\203\255\350\213\245\346\230\225/20240524 \347\247\273\345\212\250\345\244\215\345\210\266.md" "b/29 \351\203\255\350\213\245\346\230\225/20240524 \347\247\273\345\212\250\345\244\215\345\210\266.md" index 1daec4a..fffcd34 100644 --- "a/29 \351\203\255\350\213\245\346\230\225/20240524 \347\247\273\345\212\250\345\244\215\345\210\266.md" +++ "b/29 \351\203\255\350\213\245\346\230\225/20240524 \347\247\273\345\212\250\345\244\215\345\210\266.md" @@ -31,6 +31,7 @@ ``` guo@hecs-28964:~/tmp$ touch test2/1.txt test2/2.txt test2/3.txt test2/4.txt test2/5.txt + guo@hecs-28964:~/tmp$ tar -czvf test2/hailiang.tar test2/1.txt test2/2.txt test2/3.txt test2/4.txt test2/5.txt ``` diff --git "a/29 \351\203\255\350\213\245\346\230\225/20240527 \347\233\270\345\257\271\350\267\257\345\276\204\345\222\214\347\273\235\345\257\271\350\267\257\345\276\204.md" "b/29 \351\203\255\350\213\245\346\230\225/20240527 \347\233\270\345\257\271\350\267\257\345\276\204\345\222\214\347\273\235\345\257\271\350\267\257\345\276\204.md" new file mode 100644 index 0000000..e600c9f --- /dev/null +++ "b/29 \351\203\255\350\213\245\346\230\225/20240527 \347\233\270\345\257\271\350\267\257\345\276\204\345\222\214\347\273\235\345\257\271\350\267\257\345\276\204.md" @@ -0,0 +1,184 @@ +相关和目录可自行创建后再操作 + +1. 在家目录下建立文件exam.c,将文件exam.c拷贝到/tmp这个目录下,并改名为 shiyan.c + + ``` + guo@hecs-28964:~/tmp$ cp ../exam.c ./shiyan.c + + ``` + + + +2. 在任何目录下回到用户主目录? + + ``` + cd + ``` + + + +3. 用长格式列出/tmp/test目录下所有的文件包括隐藏文件? + + ``` + guo@hecs-28964:~/tmp$ ls -A test/ + + ``` + + + +4. /tmp/test2目录下,创建5个文件分别是 1.txt 2.txt 3.txt 4.txt 5.txt,压缩这5个文件,压缩包的名字是hailiang.tar + + ``` + guo@hecs-28964:~/tmp$ touch test2/{1..5}.txt + guo@hecs-28964:~/tmp$ tar -czvf test2/hailiang.tar test2/1.txt test2/2.txt test2/3.txt test2/4.txt test2/5.txt + + tar -czvf 压缩包名 被压缩的文件 + tar -czvf hailiang.tar 1.txt 2.txt 3.txt 4.txt 5.txt + ``` + + + +5. 当前目录,建立文件 file1.txt 并更名为 file2.txt? + + ``` + guo@hecs-28964:~/tmp$ touch file1.txt && mv file1.txt file2.txt + ``` + + + +6. 当前目录,用vim建立文件bbbb.txt 并将用户名的加入其中保存退出? + + ``` + guo@hecs-28964:~/tmp$ vim bbbb.txt + wq + ``` + + + +7. 将家目录中扩展名为txt、doc和bak的文件全部复制到/tmp/test目录中? + + ``` + guo@hecs-28964:~/tmp$ cp ../*.txt ../*.doc ../*.bak test + ``` + + + +8. 将文件file1.txt从当前目录移动到家目录的/docs中。 + + ``` + guo@hecs-28964:~/tmp$ sudo mv file1.txt ./../docs + ``` + + + +9. 复制文件file2.txt从当前目录到家目录/backup中。 + + ``` + cp file2.txt ./../backup/ + ``` + + + +10. 将家目录/docs中的所有文件和子目录移动到家目录/archive中。 + + ``` + mv ~/docs/* ./../archive/ + ``` + + + +11. 复制家目录/photos及其所有内容到家目录/backup中。 + + ``` + cp -r ./../photos/* ./../backup/ + ``` + + + +12. 将文件家目录/docs/report.doc移动到家目录/papers中,并将其重命名为final_report.doc。 + + ``` + mv ./../docs/report.doc ./../papers/final_report.doc + ``` + + + +13. 在家目录/docs中创建一个名为notes.txt的空文件,并将其复制到目录家目录/backup中。 + + ``` + cp ./../docs/notes.txt ./../backup/ + ``` + + + +14. 复制家目录/images中所有以.jpg结尾的文件到家目录/photos中。 + + ``` + cp ./../images/*.jpg ./../photos/ + ``` + + + +15. 将文件家目录/docs/file1.txt和家目录/docs/file2.txt复制到家目录/backup中。 + + ``` + cp ./../docs/file1*.txt ./../backup/ + ``` + + + +16. 将家目录/docs中的所有.txt文件复制到家目录/text_files中。 + + ``` + cp ./../docs/*.txt ./../text_files/ + ``` + + + +17. 将家目录/docs中的所有文件移动到家目录/temp中,并且如果文件已存在,则覆盖它们。 + + ``` + mv ./../docs/* ./../temp/ + ``` + + + +18. 将家目录/docs中的所有文件移动到家目录/archive中,并且在移动时显示详细的移动信息。 + + ``` + mv -v ./../docs/* ./../archive/ + ``` + + + +19. 复制家目录/docs中的所有子目录及其内容到家目录/backup中。 + + ``` + cp -r ./../docs/*/ ./../backup/ + ``` + + + +20. 将家目录/docs中的所有文件和子目录移动到家目录/backup中,但排除文件名以"temp_"开头的文件。 + + ``` + mv docs/!(temp_*) backup/ + ``` + + + +21. 将目录/docs/report.txt移动到家目录/archive中,但如果目标目录中已存在同名文件,则不直接覆盖,先备份同名文件为report.txt_bak。 + + ``` + mv -bS _bak ./../docs/report.txt ./../archive + ``` + + + +22. 将家目录/docs中所有以.pdf结尾的文件复制到家目录/pdf_files中,并且如果目标目录中已存在同名文件,则忽略它们。 + + ``` + cp -f ./../docs/*.pdf ./../pdf_files/ + ``` + + \ No newline at end of file -- Gitee From 7cfa67d7767581b66e030f64ba03edf6fe95193a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E8=8B=A5=E6=98=95?= <2175179136@qq.com> Date: Wed, 29 May 2024 19:16:28 +0800 Subject: [PATCH 2/2] 29 grx --- .../20240528 \346\237\245\350\257\242.md" | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 "29 \351\203\255\350\213\245\346\230\225/20240528 \346\237\245\350\257\242.md" diff --git "a/29 \351\203\255\350\213\245\346\230\225/20240528 \346\237\245\350\257\242.md" "b/29 \351\203\255\350\213\245\346\230\225/20240528 \346\237\245\350\257\242.md" new file mode 100644 index 0000000..055f5e1 --- /dev/null +++ "b/29 \351\203\255\350\213\245\346\230\225/20240528 \346\237\245\350\257\242.md" @@ -0,0 +1,161 @@ + + +# 笔记 + +### find 实时且递归的命令 + +find 目录/路径 -name "文件名" + +​ -type f(文件)/d(目录) + +​ -atime(访问时间)/ctime(创建时间)/mtime(修改时间)+/-n + +​ -empty(空文件)/ -size +/-n + +### grep 不递归 + +grep + "关键字" + 文件 + +grep -r + "关键字" + 目录/* 显示文件名 + +### which + +1. 找它的文件路径 +2. 用来检测有没有这个命令 + +### whereis 找可执行文件的 + +1. 路径 +2. 配置文件 +3. 源代码 +4. 手册 + +### type + 命令:显示命令的类型 + +### stat:显示文件或文件系统的详细信息,包括大小、权限、修改时间等 + +### locate:第三方 + +### 补充 + +1. *代表任意可见的内容文件和目录 +2. 命令a>文件b:将命令a结果保存到文件b +3. 命令a>>文件b:将命令a结果追加到文件b末尾 +4. 命令a && 命令b: 命令a执行接下来执行命令b +5. 命令a || 命令b:如果a执行成功,b不执行,反之,a失败,才执行b +6. find 命令 -exec 命令b:将find找到的结果以0的形式传递给命令b做参数 +7. {1..5}有规律的命名 + + + +# 作业 + +### 操作题 + +1. **查找当前目录及其子目录中所有扩展名为 `.log` 的文件**: + + ```bash + guo@hecs-28964:~$ find -name "*.log" -type f + + ``` + +2. **在 `/var/logs` 目录及其子目录中查找所有包含关键字 `error` 的文件,并显示匹配的行**: + ```bash + guo@hecs-28964:~$ grep -rH "error" /var/logs + + ``` + +3. **在 `/home/guo/docs` 目录中查找文件名包含 `report` 的所有文件**: + + ```bash + guo@hecs-28964:~$ find /home/guo/docs/ -name "report.*" + ``` + +4. **查找 `/etc` 目录中最近7天内修改过的文件**: ???????? + + ```bash + guo@hecs-28964:~$ find /ect -mtime -7 + find: ‘/ect’: No such file or directory //?? + + + guo@hecs-28964:/$ find -mtime -7 + ``` + +5. **显示 `/usr/bin` 目录中名为 `python` 的可执行文件的路径**: + ```bash + guo@hecs-28964:/$ whereis python + python: /usr/bin/python3.9 /usr/bin/python3.9-config /usr/lib/python3.9 /usr/lib/python2.7 /etc/python3.9 /usr/local/lib/python3.9 /usr/include/python3.9 + + ``` + +6. **查找系统中名为 `ls` 的命令及其手册页位置**: ????? 没有命令及其手册页位置 + + ```bash + guo@hecs-28964:/$ whereis ls + ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz + + ``` + +7. **查找当前目录中包含关键字 `TODO` 的所有文件,并显示匹配的行和文件名**: + + ```bash + guo@hecs-28964:~$ grep -H "TODO" ./* + ./a.txt:TODO + grep: ./backup: Is a directory + grep: ./docs: Is a directory + grep: ./tmp: Is a directory + + ``` + +8. **在 `/home/guo/projects` 目录中查找所有包含关键字 `function` 的 `.js` 文件**: + + ```bash + guo@hecs-28964:~$ grep -H "function" projects/* + projects/a.js:function + ``` + +9. **查找并显示当前目录及其子目录中所有空文件**: + ```bash + guo@hecs-28964:~$ find -empty + ``` + +10. **在 `/var/www` 目录中查找包含关键字 `database` 的所有文件,并只显示文件名**: ???显示文件名 + ```bash + guo@hecs-28964:~$ grep -H "database" /var/www/* + + ``` + +### 综合操作题 + +**综合操作题:** + +假设你在一个名为 `/home/guo/workspace` 的目录中工作。你需要完成以下任务: + +1. 查找该目录中所有扩展名为 `.conf` 的文件。 +2. 在这些 `.conf` 文件中查找包含关键字 `server` 的行。 +3. 将包含关键字 `server` 的文件名和匹配的行保存到一个名为 `server_lines.txt` 的文件中。 + +**预期命令步骤:** + +1. 查找所有扩展名为 `.conf` 的文件: + ```bash + guo@hecs-28964:~$ find -name "*.conf" + ./workspace/b.conf + ./workspace/d.conf + ./workspace/a.conf + ./workspace/c.conf + ``` + +2. 在这些 `.conf` 文件中查找包含关键字 `server` 的行: + ```bash + guo@hecs-28964:~$ grep "server" workspace/* + workspace/a.conf:1 server + workspace/b.conf:2 server + ``` + +3. 将结果保存到 `server_lines.txt` 文件中: + ```bash + guo@hecs-28964:~$ grep "server" workspace/* >workspace/server_lines.txt + ``` + +通过这套操作题和综合操作题,你可以全面地了解和应用Linux系统中与文件和内容查询相关的常用命令。 \ No newline at end of file -- Gitee