From 87cc63cca31eb075c10291e80f5622c103f19e02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E9=9B=85=E8=AF=97?= <1101928181@qq.com> Date: Sat, 25 May 2024 22:28:29 +0800 Subject: [PATCH] 0525 --- .../20240525_\344\275\234\344\270\232.md" | 202 ++++++++++++++++++ ...35\345\257\271\350\267\257\345\276\204.md" | 27 +++ 2 files changed, 229 insertions(+) create mode 100644 "45\351\253\230\351\233\205\350\257\227/20240525_\344\275\234\344\270\232.md" create mode 100644 "45\351\253\230\351\233\205\350\257\227/20240525_\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/45\351\253\230\351\233\205\350\257\227/20240525_\344\275\234\344\270\232.md" "b/45\351\253\230\351\233\205\350\257\227/20240525_\344\275\234\344\270\232.md" new file mode 100644 index 0000000..a40b90b --- /dev/null +++ "b/45\351\253\230\351\233\205\350\257\227/20240525_\344\275\234\344\270\232.md" @@ -0,0 +1,202 @@ +相关和目录可自行创建后再操作 + +第一次全部使用绝对路径 + +第二次全部使用相对路径,要求将当前路径设置为/tmp + +1. 在家目录下建立文件exam.c,将文件exam.c拷贝到/tmp这个目录下,并改名为 shiyan.c + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ touch exam.c + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ mkdir tmp + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ cp exam.c /tmp/shiyan.c + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ cp ./../exam.c ./shiyan.c + ``` + +2. 在任何目录下回到用户主目录? + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ cd ~ + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ cd ./../ + ``` + +3. 用长格式列出/tmp/test目录下所有的文件包括隐藏文件? + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ ls -la /tmp/test/ + total 8 + drwxr-xr-x 2 gaoyashi gaoyashi 4096 May 25 15:59 . + drwxrwxrwt 10 root root 4096 May 25 15:59 .. + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ ls -la ./test/ + total 8 + drwxr-xr-x 2 gaoyashi gaoyashi 4096 May 25 17:08 . + drwxr-xr-x 3 gaoyashi gaoyashi 4096 May 25 17:08 .. + ``` + +4. /tmp/test2目录下,创建5个文件分别是 1.txt 2.txt 3.txt 4.txt 5.txt,压缩这5个文件,压缩包的名字是hailiang.tar + + ``` + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ touch /tmp/test2/{1.txt,2.txt,3.txt,4.txt,5.txt} + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ tar -czvf /tmp/test2/haililang + .tar /tmp/test2 + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ touch ./test2/{1.txt,2.txt,3.txt,4.txt,5.txt} + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ tar -czvf ./test2/hailiang.tar ./test2/* + + ``` + +5. 当前目录,建立文件 file1.txt 并更名为 file2.txt? + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ mv file1.txt file2.txt + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ touch ./file1.txt + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ mv ./file1.txt file2.txt + ``` + +6. 当前目录,用vim建立文件bbbb.txt 并将用户名的加入其中保存退出? + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ vim bbbb.txt + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ vim ./bbbb.txt + ``` + +7. 将家目录中扩展名为txt、doc和bak的文件全部复制到/tmp/test目录中? + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ cp ~/{*.txt,*.doc,*.bak} /tmp/test + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ cp ./../{*.txt,*.doc,*.bak} ./test + ``` + +8. 将文件file1.txt从当前目录移动到家目录的/docs中。 + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ mv file1.txt ~/docs/ + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ mv ./file1.txt ./../docs/ + ``` + +9. 复制文件file2.txt从当前目录到家目录/backup中。 + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ cp file2.txt ~/backup/ + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ cp ./file2.txt ./../backup/ + ``` + +10. 将家目录/docs中的所有文件和子目录移动到家目录/archive中。 + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ mv ~/docs/* ~/archive/ -r + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ mv ./../docs/* ./../archive/ -r + ``` + +11. 复制家目录/photos及其所有内容到家目录/backup中。 + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ cp ~/photos/* ~/backup/ + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ cp ./../photos/* ./../backup/ + ``` + +12. 将文件家目录/docs/report.doc移动到家目录/papers中,并将其重命名为final_report.doc。 + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ mv ~/docs/report.doc ~/papers/final_report.doc + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ mv ./../docs/report.doc ./../papers/final_report.doc + ``` + +13. 在家目录/docs中创建一个名为notes.txt的空文件,并将其复制到目录家目录/backup中。 + + ``` + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ touch ~/docs/notes.txt + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ cp ~/docs/notes.txt ~/backup/ + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ touch ./../docs/notes.txt + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ cp ./../docs/notes.txt ./../backup/ + ``` + +14. 复制家目录/images中所有以.jpg结尾的文件到家目录/photos中。 + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ cp ~/images/*.jpg ~/photos/ + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ cp ./../images/*.jpg ./../photos/ + ``` + +15. 将文件家目录/docs/file1.txt和家目录/docs/file2.txt复制到家目录/backup中。 + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ cp ~/docs/{file1.txt,file2.txt} ~/backup/ + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ cp ./../docs/{file1.txt,file2.txt} ./../backup/ + ``` + +16. 将家目录/docs中的所有.txt文件复制到家目录/text_files中。 + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ cp ~/docs/*.txt ~/text_files/ + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ cp ./../docs/*.txt ./../text_files/ + ``` + +17. 将家目录/docs中的所有文件移动到家目录/temp中,并且如果文件已存在,则覆盖它们。 + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ mv ~/docs/* ~/temp/ -f + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ mv ./../docs/* ./../temp/ -f + ``` + +18. 将家目录/docs中的所有文件移动到家目录/archive中,并且在移动时显示详细的移动信息。 + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ mv ~/docs/* ~/archive/ -v + renamed '/home/gaoyashi/docs/file1.txt' -> '/home/gaoyashi/archive/file1.txt' + renamed '/home/gaoyashi/docs/file2.txt' -> '/home/gaoyashi/archive/file2.txt' + renamed '/home/gaoyashi/docs/notes.txt' -> '/home/gaoyashi/archive/notes.txt' + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ mv ./../docs/* ./../archive/ -v + ``` + + +19. 复制家目录/docs中的所有子目录及其内容到家目录/backup中。 + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ cp ~/docs/* ~/backup/ -r + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ cp ./../docs/* ./../backup/ -r + ``` + +20. 将家目录/docs中的所有文件和子目录移动到家目录/backup中,但排除文件名以"temp_"开头的文件。 + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ mv ~/docs/!(temp_*) ~/backup/ + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ mv ./../docs/!(temp_*) ./../backup/ + ``` + +21. 将目录/docs/report.txt移动到家目录/archive中,但如果目标目录中已存在同名文件,则不直接覆盖,先备份同名文件为report.txt_bak。 + + ``` + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ mv ~/docs/report.txt ~/archive/report.txt_bak -b + + gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ mv ./../docs/report.txt ./../archive/report.txt_bak -b + ``` + +22. 将家目录/docs中所有以.pdf结尾的文件复制到家目录/pdf_files中,并且如果目标目录中已存在同名文件,则忽略它们。 + +``` +gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ cp ~/docs/*.pdf ~/pdf_files/ -n + +gaoyashi@iZf8zh6micauwcw30jcu5tZ:~/tmp$ cp /docs/*.pdf ./../pdf_files/ -n +``` diff --git "a/45\351\253\230\351\233\205\350\257\227/20240525_\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/45\351\253\230\351\233\205\350\257\227/20240525_\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..6d42298 --- /dev/null +++ "b/45\351\253\230\351\233\205\350\257\227/20240525_\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,27 @@ +### 绝对路径与相对路径 + +#### 1. 绝对路径 +**定义**:从根目录 `/` 开始的完整路径,用于唯一确定文件或目录的位置。 + +**特点**: + +- 以 `/` 开头 +- 与当前工作目录无关 + +#### 2. 相对路径 +**定义**:相对于当前工作目录的路径,用于在当前目录的基础上指向文件或目录。 + +**特点**: + +- 不以 `/` 开头 +- 依赖于当前工作目录 + +**特殊符号**: + +- `.` 表示当前目录 ./ +- `..` 表示上一级目录../ + +### 3.总结 + +- **绝对路径**始终从根目录开始,适合在需要唯一标识文件或目录位置时使用。 +- **相对路径**从当前工作目录出发,适合在命令行交互和项目内部文件操作时使用。 -- Gitee