diff --git "a/07 \347\216\213\345\217\221\346\247\220/2024-5-27\347\233\270\345\205\263\345\222\214\347\233\256\345\275\225\345\217\257\350\207\252\350\241\214\345\210\233\345\273\272\345\220\216\345\206\215\346\223\215\344\275\234.md" "b/07 \347\216\213\345\217\221\346\247\220/2024-5-27\347\233\270\345\205\263\345\222\214\347\233\256\345\275\225\345\217\257\350\207\252\350\241\214\345\210\233\345\273\272\345\220\216\345\206\215\346\223\215\344\275\234.md" new file mode 100644 index 0000000000000000000000000000000000000000..33d7428e470acff99760c4d9a9bc6feeb31ea3ff --- /dev/null +++ "b/07 \347\216\213\345\217\221\346\247\220/2024-5-27\347\233\270\345\205\263\345\222\214\347\233\256\345\275\225\345\217\257\350\207\252\350\241\214\345\210\233\345\273\272\345\220\216\345\206\215\346\223\215\344\275\234.md" @@ -0,0 +1,305 @@ +```` +相关和目录可自行创建后再操作 + +1. 在家目录下建立文件exam.c,将文件exam.c拷贝到/tmp这个目录下,并改名为 shiyan.c + + ```bash + wmm@hecs-288034:~$ mv exam.c /tmp/shiyan.c + wmm@hecs-288034:~$ ls /tmp + backup + file1.txt + file1.txt_bak + hsperfdata_root + wmm@hecs-288034:~$ mv exam.c ~/tmp/shiyan.c + ``` + + + +2. 在任何目录下回到用户主目录? + + ```bash + wmm@hecs-288034:~$ cd ~ + ``` + + + +3. 用长格式列出/tmp/test目录下所有的文件包括隐藏文件? + + ```bash + wmm@hecs-288034:~$ ls -la /tmp + total 48 + drwxrwxrwt 12 root root 4096 May 27 11:08 . + drwxr-xr-x 19 root root 4096 May 23 19:01 .. + -rw-r--r-- 1 wmm wmm 0 May 25 14:50 backup + -rw-r--r-- 1 wmm wmm 0 May 25 14:48 file1.txt + -rw-r--r-- 1 wmm wmm 0 May 25 14:48 file1.txt_bak + drwxrwxrwt 2 root root 4096 May 13 18:52 .font-unix + drwxr-xr-x 2 root root 4096 May 13 18:53 hsperfdata_root + drwxrwxrwt 2 root root 4096 May 13 18:52 .ICE-unix + drwxr-xr-x 2 wmm wmm 4096 May 25 13:33 moved_proj_b + -rw-r--r-- 1 wmm wmm 0 May 25 14:58 new_file1.txt + -rw-r--r-- 1 wmm wmm 0 May 27 11:04 shiyan.c + drwx------ 3 root root 4096 May 13 18:53 systemd-private-358e23a535d84b70894b4cd6460e30ec-chrony.service-WJlkyi + drwx------ 3 root root 4096 May 13 18:53 systemd-private-358e23a535d84b70894b4cd6460e30ec-ModemManager.service-BYz7ig + drwx------ 3 root root 4096 May 13 18:53 systemd-private-358e23a535d84b70894b4cd6460e30ec-systemd-logind.service-e2Tqvf + drwxrwxrwt 2 root root 4096 May 13 18:52 .Test-unix + drwxrwxrwt 2 root root 4096 May 13 18:52 .X11-unix + drwxrwxrwt 2 root root 4096 May 13 18:52 .XIM-unix + + + wmm@hecs-288034:~$ ls -la ~/tmp + ``` + + + +4. /tmp/test2目录下,创建5个文件分别是 1.txt 2.txt 3.txt 4.txt 5.txt,压缩这5个文件,压缩包的名字是hailiang.tar + +```bash +wmm@hecs-288034:/tmp$ tar -zcvf hailiang.tar *.txt +1.txt +2.txt +3.txt +4.txt +5.txt +file1.txt +new_file1.txt + + +``` + + + +1. 当前目录,建立文件 file1.txt 并更名为 file2.txt? + +```bash +wmm@hecs-288034:/tmp$ touch file1.txt && mv file1.txt file2.txt + + +``` + + + +1. 当前目录,用vim建立文件bbbb.txt 并将用户名的加入其中保存退出? + +```bash +wmm@hecs-288034:/tmp$ vim bbbb.txt +wmm@hecs-288034:/tmp$ cat bbbb.txt +wmm +wmm@hecs-288034:/tmp$ +``` + + + +1. 将家目录中扩展名为txt、doc和bak的文件全部复制到/tmp/test目录中? + + ```bash + wmm@hecs-288034:~$ cp ~/*.txt ~/*.doc ~/*.bak /tmp/test + + wmm@hecs-288034:~$ cp *.txt *.doc *.bak ~/tmp/test + ``` + +8. 将文件file1.txt从当前目录移动到家目录的/docs中。 + +```bash + +```bash + +```bash +wmm@hecs-288034:~$ mv /tmp/file1.txt_bak ~/docs +wmm@hecs-288034:~$ ls docs +file1.txt_bak + +wmm@hecs-288034:~$ mv /tmp/file1.txt_bak ~/docs + + + +``` + +3. 复制文件file2.txt从当前目录到家目录/backup中。 + + ```bash + wmm@hecs-288034:~$ mkdir backup && mv /tmp/file2.txt ~/backup + wmm@hecs-288034:~$ ls backup + file2.txt + wmm@hecs-288034:~$ + + ``` + +4. 将家目录/docs中的所有文件和子目录移动到家目录/archive中。 + + ```bash + ```bash + wmm@hecs-288034:~$ sudo mv ~/docs/* ~/archive/ + wmm@hecs-288034:~$ ls -R ~/archive + .: + file1.txt + ``` + + wmm@hecs-288034:~$ ~/tmp$ sudo mv ~/docs/* ./../archive/ + wmm@hecs-288034:~$ ~/tmp$ ls -R ./../archive + .: + file1.txt + ``` + +5. 复制家目录/photos及其所有内容到家目录/backup中。 + + ```bash + wmm@hecs-288034:~$ cp ~/photos/* ~/backup/ + + wmm@hecs-288034:~$ cp ~/photos/* ./../backup/ + ``` + +6. 将文件家目录/docs/report.doc移动到家目录/papers中,并将其重命名为final_report.doc。 + + ```bash + wmm@hecs-288034:~$ mv docs/report,doc parpers/final_report.doc + wmm@hecs-288034:~$ ls + archive backup docs parpers photos + wmm@hecs-288034:~$ ls parpers/ + final_report.doc + + wmm@hecs-288034:~$ mv ./../docs/report.doc ./../parpers/final_report.doc + wmm@hecs-288034:~$ ls ./../parpers + archive backup docs parpers photos + wmm@hecs-288034:~$ ls parpers/ + final_report.doc + wmm@hecs-288034:~$ + + + ``` + +7. 在家目录/docs中创建一个名为notes.txt的空文件,并将其复制到目录家目录/backup中。 + +```bash +wmm@hecs-288034:~$ mv docs/note.txt ./backup/ + +wmm@hecs-288034:~$ mv ~/docs/note.txt ./backup/ + + +``` + +1. 复制家目录/images中所有以.jpg结尾的文件到家目录/photos中。 + +```bash +wmm@hecs-288034:~$ cp ./images/*.jpg ./photos/ + +wmm@hecs-288034:~/tmp$ cp ./../images/*.jpg ./../photos/ + + +``` + +1. 将文件家目录/docs/file1.txt和家目录/docs/file2.txt复制到家目录/backup中。 + +```bash + wmm@hecs-288034:~$ cp docs/file*.txt ~/backup/ + wmm@hecs-288034:~$ ls ~/backup + file1.txt file2.txt la.png notes.txt + + + wmm@hecs-288034:~/tmp$ cp ./../docs/file1*.txt ./../backup/ + wmm@hecs-288034:~/tmp$ ls ./../backup + file1.txt file2.txt la.png notes.txt +``` + +1. 将家目录/docs中的所有.txt文件复制到家目录/text_files中。 + +```bash + wmm@hecs-288034:~$ cp docs/*.txt ~/text_files/ + wmm@hecs-288034:~$ ls ~/text_files/ + file1.txt file2.txt notes.txt + + wmm@hecs-288034:~/tmp$ cp ./../docs/*.txt ./../text_files/ + wmm@hecs-288034:~/tmp$ ls ./../text_files + file1.txt file2.txt notes.txt +``` + + + +1. 将家目录/docs中的所有文件移动到家目录/temp中,并且如果文件已存在,则覆盖它们。 + +```bash + + wmm@hecs-288034:~$ mv docs/* ~/temp/ + wmm@hecs-288034:~$ ls ~/temp + file1.txt file2.txt li.md notes.txt + + + + wmm@hecs-288034:~/tmp$ mv ./../docs/* ./../temp/ + wmm@hecs-288034:~/tmp$ ls ./../temp + file1.txt file2.txt li.md notes.txt + +``` + +1. 将家目录/docs中的所有文件移动到家目录/archive中,并且在移动时显示详细的移动信息。 + +```bash + + wmm@hecs-288034:~$ mv -v docs/* archive/ + renamed 'docs/li.md' -> 'archive/li.md' + + + + wmm@hecs-288034:~/tmp$ mv -v ./../docs/* ./../archive/ + renamed './../docs/l.md' -> './../archive/l.md' + +``` + +1. 复制家目录/docs中的所有子目录及其内容到家目录/backup中。 + +```bash +wmm@hecs-288034:~$ sudo cp -r docs/*/ backup/ + wmm@hecs-288034:~$ ls ~/backup + + + wmm@hecs-288034:~/tmp$ sudo cp -r ./../docs/*/ ./../backup/ + wmm@hecs-288034:~/tmp$ cd ./../backup/ + f +``` + +1. 将家目录/docs中的所有文件和子目录移动到家目录/backup中,但排除文件名以"temp_"开头的文件。 + +```bash + + wmm@hecs-288034:~$ sudo mv docs/!(temp_*) backup/ + lala@hecs-393504:~/backup$ ls + file1.txt file2.txt la la.jpg la.png list.pdf notes.txt temp_la + + + + wmm@hecs-288034:~/tmp$ sudo mv ./../docs/!(temp_*) ./../backup/ + wmm@hecs-288034:~/tmp$ cd ./../backup/ + file1.txt file2.txt la la.jpg la.png list.pdf notes.txt temp_la + +``` + +1. 将目录/docs/report.txt移动到家目录/archive中,但如果目标目录中已存在同名文件,则不直接覆盖,先备份同名文件为report.txt_bak。 + +```bash + + wmm@hecs-288034:~$ sudo mv -bS _bak docs/report.txt archive + wmm@hecs-288034:~$ ls ~/archive + file1.txt li.md report.txt report.txt_bak + + + + wmm@hecs-288034:~/tmp$ sudo mv -bS _bak ./../docs/report.txt ./../archive + wmm@hecs-288034:~/tmp$ ls ./../archive/ + file1.txt li.md report.txt report.txt_bak + +``` + +1. 将家目录/docs中所有以.pdf结尾的文件复制到家目录/pdf_files中,并且如果目标目录中已存在同名文件,则忽略它们。 + +```bash + wmm@hecs-288034:~$ sudo cp -f docs/*.pdf pdf_files/ + wmm@hecs-288034:~$ ls ~/pdf_files + list.pdf + + + + wmm@hecs-288034:~/tmp$ sudo cp -f ./../docs/*.pdf ./../pdf_files/ + wmm@hecs-288034:~/tmp$ ls ./../pdf_files + list.pdf +```` +