quest: rm, fix copy (stages removed by AI)

This commit is contained in:
Justin Lin committed 2025-04-26 12:10:53 +08:00
1 parent fda0357a73
commit 67e84d8cf9
11 files changed
+392 -6

No files matched your search

+122 -6
View File
@@ -225,15 +225,131 @@ stages:
response:
content: |
你成功查看到 `world2.txt` 的內容了!
正如我們所見,`world2.txt` 的內容跟 `world.txt` 一模一樣。
恭喜你完成了這個關卡!
輸入 `echo finish` 來進入下一個關卡吧!
hint: 輸入 `echo finish` 來進入下一個關卡
`world2.txt` 的內容跟 `world.txt` 一模一樣。
接下來我們要來學習如何複製資料夾。
現在目錄下有一個 `notes` 資料夾,裡面有一個 `note.txt` 的檔案。
我們要能整個資料夾包含裡面的檔案一起複製到 `notes2`。
跟複製單一檔案不一樣的是,複製資料夾時,我們要加上 `-r` 的選項(recursive)代表將資料夾中的所有檔案都一起複製。
在使用指令時,如果想要調整指令的行為,可以在指令後面加上選項。
選項的格式通常是 `-` 加上一個字母,例如 `-r`。
選項擺放的位置沒有特別的限制,通常會跟在指令的後面,置於檔案名稱的前面。
請你使用 `cp -r notes notes2` 來複製 `notes` 資料夾到 `notes2`。
hint: |
使用 `cp -r notes notes2` 來複製 `notes` 資料夾到 `notes2`
記得要加上 `-r` 的選項來複製所有檔案
- id: END
name: 恭喜你完成了所有任務!
- id: cp-notes
name: 複製 `notes` 資料夾到 `notes2`
requirements:
- cat-world2
condition:
pwd: /home/commander
command: cp -r notes notes2
files:
- path: /home/commander/notes2
type: directory
exists: true
- path: /home/commander/notes2/note.txt
type: file
exists: true
exceptions:
- id: wrong_directory
condition:
not:
pwd: /home/commander
response:
content: |
你不在 `/home/commander` 資料夾裡。
請使用 `cd /home/commander` 來返回 `/home/commander` 資料夾。
- id: missing_recursive
condition:
command: cp notes notes2
response:
content: |
你忘記加上 `-r` 的參數了嗎?
請輸入 `cp -r notes notes2` 來複製 `notes` 資料夾到 `notes2`
response:
content: |
你成功複製 `notes` 資料夾到 `notes2` 了!
我們打開來確認一下 `notes2` 資料夾的內容吧!
hint: 使用 `ls notes2` 來查看 `notes2` 資料夾的內容
- id: ls-notes2
name: 查看 `notes2` 資料夾的內容
requirements:
- cp-notes
condition:
pwd: /home/commander
command: ls notes2
output: note.txt
exceptions:
- id: wrong_directory
condition:
not:
pwd: /home/commander
response:
content: |
你不在 `/home/commander` 資料夾裡。
請使用 `cd /home/commander` 來返回 `/home/commander` 資料夾。
response:
content: |
你成功查看到 `notes2` 資料夾的內容了!
我們可以看到,整個 `notes` 資料夾包含裡面的檔案,都被複製到 `notes2` 資料夾了。
那麼最後我們要來試試看,如果複製一個檔案到已經存在的檔案會發生什麼事。
請把 `hello.txt` 複製到 `world.txt` 看看會發生什麼事。
hint: 使用 `cp hello.txt world.txt` 來複製 `hello.txt` 到 `world.txt`
- id: cp-overwrite
name: 複製 `hello.txt` 到 `world.txt`
requirements:
- ls-notes2
condition:
pwd: /home/commander
command: cp hello.txt world.txt
exceptions:
- id: wrong_directory
condition:
not:
pwd: /home/commander
response:
content: |
你不在 `/home/commander` 資料夾裡。
請使用 `cd /home/commander` 來返回 `/home/commander` 資料夾。
response:
content: |
你成功複製 `hello.txt` 到 `world.txt` 了!
我們打開來確認一下 `world.txt` 的內容吧!
hint: 使用 `cat world.txt`
- id: check-world
name: 檢查 `world.txt` 的內容
requirements:
- cp-overwrite
condition:
pwd: /home/commander
command: cat world.txt
output: Hello
exceptions:
- id: wrong_directory
condition:
not:
pwd: /home/commander
response:
content: |
你不在 `/home/commander` 資料夾裡。
請使用 `cd /home/commander` 來返回 `/home/commander` 資料夾。
response:
content: |
`world.txt` 的內容變成 `Hello` 了!
這是因為,當我們複製檔案時,如果目的檔案已經存在,那麼目的檔案的內容就會被覆蓋掉。
所以在複製檔案的時候,要特別注意目的檔案是否已經存在,否則可能會不小心把資料弄丟。
以上就是複製檔案的基本操作!
請輸入 `echo finish` 來完成這個關卡。
- id: finish
name: 恭喜你完成了所有任務!
requirements:
- check-world
condition:
command: echo finish
response: