From 184b4c8b8d90cf01c057955f3742319a93402939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=AD=A3=E6=A5=A0?= <12461668+kkkjj2222222256@user.noreply.gitee.com> Date: Wed, 29 May 2024 13:16:13 +0000 Subject: [PATCH] =?UTF-8?q?=E9=99=88=E6=AD=A3=E6=A5=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈正楠 <12461668+kkkjj2222222256@user.noreply.gitee.com> --- .../20240529\344\275\234\344\270\232.md" | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 "03\351\231\210\346\255\243\346\245\240/20240529\344\275\234\344\270\232.md" diff --git "a/03\351\231\210\346\255\243\346\245\240/20240529\344\275\234\344\270\232.md" "b/03\351\231\210\346\255\243\346\245\240/20240529\344\275\234\344\270\232.md" new file mode 100644 index 0000000..e6187bc --- /dev/null +++ "b/03\351\231\210\346\255\243\346\245\240/20240529\344\275\234\344\270\232.md" @@ -0,0 +1,95 @@ +```` +### 操作题 + +1. **查找当前目录及其子目录中所有扩展名为 `.log` 的文件**: + + ```bash + find ./ -name '.log' -type + ``` + +2. **在 `/var/logs` 目录及其子目录中查找所有包含关键字 `error` 的文件,并显示匹配的行**: + + ```bash + grep -r 'error' /var/logs + ``` + +3. **在 `/home/user/docs` 目录中查找文件名包含 `report` 的所有文件**: + + ```bash + find /home/user/docs -name 'report' -type f + ``` + +4. **查找 `/etc` 目录中最近7天内修改过的文件**: + + ```bash + find /etc -type f mtime -7 + ``` + +5. **显示 `/usr/bin` 目录中名为 `python` 的可执行文件的路径**: + + ```bash + find /use/bin -name 'python' exec which {} \; + ``` + +6. **查找系统中名为 `ls` 的命令及其手册页位置**: + + ```bash + whereis ls + ``` + +7. **查找当前目录中包含关键字 `TODO` 的所有文件,并显示匹配的行和文件名**: + + ``` bash + grep -r 'TODO' ./ + ``` + +8. **在 `/home/user/projects` 目录中查找所有包含关键字 `function` 的 `.js` 文件**: + + ```bash + grep 'function.js' /home/user/projects + ``` + +9. **查找并显示当前目录及其子目录中所有空文件**: + + ```bash + find ./ -empty -type f + ``` + +10. **在 `/var/www` 目录中查找包含关键字 `database` 的所有文件,并只显示文件名**: + + ```bash + find /var/www -type f -exec grep -l 'database' {} \; + ``` + +### 综合操作题 + +**综合操作题:** + +假设你在一个名为 `/home/user/workspace` 的目录中工作。你需要完成以下任务: + +1. 查找该目录中所有扩展名为 `.conf` 的文件。 +2. 在这些 `.conf` 文件中查找包含关键字 `server` 的行。 +3. 将包含关键字 `server` 的文件名和匹配的行保存到一个名为 `server_lines.txt` 的文件中。 + +**预期命令步骤:** + +1. 查找所有扩展名为 `.conf` 的文件: + + ```bash + find /home/user/workspace -name '.conf' -type f + ``` + +2. 在这些 `.conf` 文件中查找包含关键字 `server` 的行: + + ```bash + find ./ -type f -name '*.conf' -exec grep -n 'server' {} \; + ``` + +3. 将结果保存到 `server_lines.txt` 文件中: + + ```bash + + ``` + +通过这套操作题和综合操作题,你可以全面地了解和应用Linux系统中与文件和内容查询相关的常用命令。 +```` -- Gitee