diff --git "a/21 \346\264\252\351\224\246\346\264\213/2024-05-29 \346\237\245\350\257\242\345\221\275\344\273\244\347\233\270\345\205\263\347\232\204\347\273\203\344\271\240.md" "b/21 \346\264\252\351\224\246\346\264\213/2024-05-29 \346\237\245\350\257\242\345\221\275\344\273\244\347\233\270\345\205\263\347\232\204\347\273\203\344\271\240.md" new file mode 100644 index 0000000000000000000000000000000000000000..9a194ced09ba199041804ae106cd311b511f5280 --- /dev/null +++ "b/21 \346\264\252\351\224\246\346\264\213/2024-05-29 \346\237\245\350\257\242\345\221\275\344\273\244\347\233\270\345\205\263\347\232\204\347\273\203\344\271\240.md" @@ -0,0 +1,79 @@ +### 操作题 + +1. **查找当前目录及其子目录中所有扩展名为 `.log` 的文件**: + + ``` + find ./ -type f -name "*.log" + ``` + +2. **在 `/var/logs` 目录及其子目录中查找所有包含关键字 `error` 的文件,并显示匹配的行**: + + ``` + find /var/logs grep "error" -type f + ``` + +3. **在 `/home/user/docs` 目录中查找文件名包含 `report` 的所有文件**: + + ``` + find /home/user/docs grep "report" + ``` + +4. **查找 `/etc` 目录中最近7天内修改过的文件**: + + ``` + find /etc -type f -ctime +7 + ``` + +5. **显示 `/usr/bin` 目录中名为 `python` 的可执行文件的路径**: + + ``` + whereis /usr/bin + ``` + +6. **查找系统中名为 `ls` 的命令及其手册页位置**: + + ``` + whereis ls + ``` + +7. **查找当前目录中包含关键字 `TODO` 的所有文件,并显示匹配的行和文件名**: + + ``` + grep -n "TODO" TODO + ``` + +8. **在 `/home/user/projects` 目录中查找所有包含关键字 `function` 的 `.js` 文件**: + + ``` + find /home/user/projects grep "function" -type f -name "*.js" + ``` + +9. **查找并显示当前目录及其子目录中所有空文件**: + + ``` + find ./ -empty -type d + ``` + +10. **在 `/var/www` 目录中查找包含关键字 `database` 的所有文件,并只显示文件名**: + + ``` + find /var/www gerp l "database" + ``` + +### 综合操作题 + +**综合操作题:** + +假设你在一个名为 `/home/user/workspace` 的目录中工作。你需要完成以下任务: + +1. 查找该目录中所有扩展名为 `.conf` 的文件。 +2. 在这些 `.conf` 文件中查找包含关键字 `server` 的行。 +3. 将包含关键字 `server` 的文件名和匹配的行保存到一个名为 `server_lines.txt` 的文件中。 + +**预期命令步骤:** + +1. 查找所有扩展名为 `.conf` 的文件: +2. 在这些 `.conf` 文件中查找包含关键字 `server` 的行: +3. 将结果保存到 `server_lines.txt` 文件中: + +通过这套操作题和综合操作题,你可以全面地了解和应用Linux系统中与文件和内容查询相关的常用命令。 \ No newline at end of file