From 35426171387e87d5f3ec90fb29a48ea3f7e0a1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=85=E5=BF=A0=E9=92=A6?= <11785125+mei-zhongqin@user.noreply.gitee.com> Date: Thu, 30 May 2024 13:21:43 +0000 Subject: [PATCH] =?UTF-8?q?08=E6=A2=85=E5=BF=A0=E9=92=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 梅忠钦 <11785125+mei-zhongqin@user.noreply.gitee.com> --- ...45\347\234\213\347\273\203\344\271\240.md" | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 "08 \346\242\205\345\277\240\351\222\246/0530 \346\226\207\344\273\266\346\237\245\347\234\213\347\273\203\344\271\240.md" diff --git "a/08 \346\242\205\345\277\240\351\222\246/0530 \346\226\207\344\273\266\346\237\245\347\234\213\347\273\203\344\271\240.md" "b/08 \346\242\205\345\277\240\351\222\246/0530 \346\226\207\344\273\266\346\237\245\347\234\213\347\273\203\344\271\240.md" new file mode 100644 index 0000000..58a578e --- /dev/null +++ "b/08 \346\242\205\345\277\240\351\222\246/0530 \346\226\207\344\273\266\346\237\245\347\234\213\347\273\203\344\271\240.md" @@ -0,0 +1,132 @@ +**以下所有操作都在家目录执行:** + +### + +1. **操作题一**:使用 `cat` 命令显示 `/etc/passwd` 文件的内容。 + + ```bash + cat /etc/passwd + ``` + +2. **操作题二**:将文件 `/etc/passwd` 的内容复制到 `passwd_bak.txt` 文件中,但不使用 `cp` 命令。 + + ```bash + cat /etc/passwd >> passwd_bak.txt + ``` + +3. **操作题三**:新建两个文件 `file1.txt` 和 `file2.txt`,分别写一些不同的内容,再将这两个文件的内容合并到一个新的文件 `file3.txt` 中。 + +```bash + cat file1.txt file2.txt > file3.txt +``` + +1. 使用命令从尾部开始显示 `bigfile.txt` 文件的内容。 + + ```bash + tac bigfile.txt + ``` + +2. 尝试找出 `bigfile.txt` 文件的最后一行内容,要使用 `tac` 命令。 + + ```bash + tac bigfile.txt | tail -n 1 + ``` + +3. 查看 `bigfile.txt` 文件的最后5行内容。 + + ```bash + tail -n 5 bigfile.txt + ``` + +4. 倒序查看 `bigfile.txt` 文件的最后5行内容。 + +```bash + tac bigfile.txt | tail -n 5 +``` + +1. **操作题一**:使用 `more` 命令查看 `bigfile.txt` 文件的内容,并在查看过程中使用空格键翻页。 + + ```bash + more bigfile.txt + ``` + +2. **操作题二**:在 `more` 命令的查看过程中,如何使用回车键来逐行查看文件内容? + + ```bash + more bigfile.txt + ``` + +3. **操作题三**:如何在 `more` 命令中搜索`bigfile.txt`特定字符串(例如 "error")并跳转到下一个匹配项? + + ```bash + more bigfile.txt /error + ``` + +### `less` 命令操作题 + +1. **操作题一**:使用 `less` 命令查看 `bigfile.txt` 文件,并快速定位到文件的末尾。 + + ```bash + less bigfile.txt + (shift + g) + ``` + +2. **操作题二**:在 `less` 命令中,如何向上和向下滚动文件内容? + + ```bash + 按上下翻 + ``` + +3. **操作题三**:在 `less` 命令中,如何搜索`bigfile.txt`一个特定的函数名(例如 `def my_function`),并查看所有匹配项? + + ```bash + /def my_function + ``` + +### `head` 命令操作题 + +1. **操作题一**:使用 `head` 命令显示 `bigfile.txt` 文件的前5行内容。 + + ```bash + head bigfile.txt -n 5 + ``` + +2. **操作题二**:将 `bigfile.txt` 的前20行内容保存到 `bigfile_20.txt` 文件中。 + + ```bash + head bigfile.txt -n 20 > bigfile_20.txt + ``` + +3. **操作题三**:如何结合 `head` 和 `grep` 命令来查找 `bigfile.txt` 文件中以 "A" 开头的前10行? + + ```bash + head |grep "A" bigfile.txt + ``` + +### `tail` 命令操作题 + +1. **操作题一**:使用 `tail` 命令显示 `bigfile.txt` 文件的最后20行内容。 + + ```bash + tail -n 20 bigfile.txt + ``` + +2. **操作题二**:如何实时跟踪一个正在写入的日志文件(如 `bigfile.txt`)的最后10行内容? + + ```bash + tail -f -n 10 bigfile.txt + ``` + +3. **操作题三**:在 `tail` 命令中,如何反向显示文件的最后10行内容(即按从旧到新的顺序显示)? + + ```bash + tail -n 10 bigfile.txt | tac + ``` + +### 综合题 + +**综合题**:假设你有一个非常大的日志文件 `bigfile.txt`,你需要找出所有包含 "ERROR" 字符串的行,并查看这些行及其之前的两行内容。 + +```bash +head | grep -B 2 "ERROR" bigfile.txt +``` -- Gitee