diff --git a/quests/permission/Dockerfile b/quests/permission/Dockerfile new file mode 100644 index 0000000..e905e4e --- /dev/null +++ b/quests/permission/Dockerfile @@ -0,0 +1,4 @@ +FROM linuxodyssey/quest-base + +COPY home ${HOME} +RUN chmod \ No newline at end of file diff --git a/quests/permission/answer.sh b/quests/permission/answer.sh new file mode 100644 index 0000000..e69de29 diff --git a/quests/permission/game.yml b/quests/permission/game.yml new file mode 100644 index 0000000..c2c5466 --- /dev/null +++ b/quests/permission/game.yml @@ -0,0 +1,253 @@ +title: 查看檔案存取權限 +instruction: | + 在這個關卡中,你將會學到: + 1. 用`ls -l`指令查看檔案的存取權限 + 2. 了解檔案存取權限的意義 + + 準備好就輸入 `echo start` 開始吧! + +requirements: + - helloworld + +stages: + - id: start + task: 輸入 `echo start` 來開始 + condition: + output: + - start + exceptions: + - condition: + command: + - ^echo$ + responses: + - type: narrative + content: + - 你忘記輸入 `start` 了嗎? + - 請輸入 `echo start` 來開始 + - catchAll: true + responses: + - type: narrative + content: + - 請輸入 `echo start` 來開始 + responses: + - type: narrative + content: + 現在我們要學習如何查看檔案的存取權限。 + 使用`ls -l`指令來查看不同檔案的存取權限吧! + + hints: + - ➤ 使用 `ls -l` 來查看檔案的存取權限 + + - id: ls-l + task: 查看檔案的存取權限 + requirements: + - start + condition: + command: + - ls -l + pwd: + - /home/commander + responses: + - type: narrative + content: + - 你成功查看到檔案的存取權限了! + - 你可以看到檔案的存取權限的左邊類似 `-rw-r--r--` 的字串。 + - 這個字串由十個字元組成,第一個字元代表檔案的類型,後面九個字元分別代表檔案的存取權限。 + - 第一個字元如果是 `-` 代表這是一個檔案,如果是 `d` 代表這是一個資料夾。 + - 後面九個字元中以三個字元一組,分別代表檔案的擁有者、群組、以及其他人的存取權限。 + - 每一組中的三個字元分別代表讀取(`r`)、寫入(`w`)、執行(`x`)的權限。 + - 如果該欄位是 `-` 則表示沒有該權限。 + - 例如 `rw-` 代表擁有讀取和寫入的權限,但沒有執行的權限; + - 而 `r-x` 代表擁有讀取和執行的權限,但沒有寫入的權限。 + + - id: read-file1 + task: 查看 `file1` 的內容 + requirements: + - ls-l + condition: + pwd: /home/commander + command: + - cat file1 + responses: + - type: narrative + content: + - 你看到 `file1` 的內容了! + - 現在試著執行看看 `file1` 吧! + + + - id: cat-continue + task: 使用 `echo continue` 來繼續 + requirements: + - cat-hello + - cat-world + condition: + command: + - echo + responses: + - type: narrative + content: + - 接下來我們要來學習複製檔案。 + - '`cp` 這個指令,是 copy 的縮寫,就是複製的意思。' + - 我們可以用 `cp [來源檔案] [目的檔案]` 的方式來複製檔案。 + - 請你使用 `cp` 來複製 `hello.txt` 到 `hello2.txt`。 + hints: + - ➤ 使用 `cp hello.txt hello2.txt` 來複製 `hello.txt` 到 `hello2.txt` + + - id: cp-hello + task: 複製 `hello.txt` 到 `hello2.txt` + requirements: + - cat-continue + condition: + command: + - ^cp hello.txt hello2.txt$ + files: + - path: hello2.txt + type: file + responses: + - type: narrative + content: + - 你成功複製 `hello.txt` 到 `hello2.txt` 了! + - 我們打開來確認一下 `hello2.txt` 的內容吧! + hints: + - ➤ 使用 `cat hello2.txt` 來查看 `hello2.txt` 的內容 + + - id: cat-hello2 + requirements: + - cp-hello + task: 查看 `hello2.txt` 的內容 + condition: + command: + - ^cat hello2.txt$ + output: + - Hello + responses: + - type: narrative + content: + - 你成功查看到 `hello2.txt` 的內容了! + - 正如我們所見,`hello2.txt` 的內容跟 `hello.txt` 一模一樣。 + - 那我們再來試試看複製 `world.txt` 到 `world2.txt` 吧! + hints: + - ➤ 使用 `cp world.txt world2.txt` 來複製 `world.txt` 到 `world2.txt` + + - id: cp-world + requirements: + - cat-hello2 + task: 複製 `world.txt` 到 `world2.txt` + condition: + command: + - ^cp world.txt world2.txt$ + files: + - path: world2.txt + type: file + responses: + - type: narrative + content: + - 你成功複製 `world.txt` 到 `world2.txt` 了! + - 我們打開來確認一下 `world2.txt` 的內容吧! + hints: + - ➤ 使用 `cat world2.txt` 來查看 `world2.txt` 的內容 + + - id: cat-world2 + requirements: + - cp-world + task: 查看 `world2.txt` 的內容 + condition: + command: + - ^cat world2.txt$ + output: + - World + responses: + - type: narrative + content: + - 你成功查看到 `world2.txt` 的內容了! + - '`world2.txt` 的內容跟 `world.txt` 一模一樣。' + - 接下來我們要來學習如何複製資料夾。 + - 現在目錄下有一個 `notes` 資料夾,裡面有一個 `note.txt` 的檔案。 + - 我們要能整個資料夾包含裡面的檔案一起複製到 `notes2`。 + - 跟複製單一檔案不一樣的是,複製資料夾時,我們要加上 `-r` 的選項(recursive)代表將資料夾中的所有檔案都一起複製。 + - 在使用指令時,如果想要調整指令的行為,可以在指令後面加上選項。 + - 選項的格式通常是 `-` 加上一個字母,例如 `-r`。 + - 選項擺放的位置沒有特別的限制,通常會跟在指令的後面,置於檔案名稱的前面。 + - 請你使用 `cp -r notes notes2` 來複製 `notes` 資料夾到 `notes2`。 + hints: + - ➤ 使用 `cp -r notes notes2` 來複製 `notes` 資料夾到 `notes2` + - ➤ 記得要加上 `-r` 的選項來複製所有檔案 + + - id: cp-notes + requirements: + - cat-world2 + task: 複製 `notes` 資料夾到 `notes2` + condition: + command: + - ^cp + files: + - path: notes2 + type: directory + - path: notes2/note.txt + type: file + responses: + - type: narrative + content: + - 你成功複製 `notes` 資料夾到 `notes2` 了! + - 我們打開來確認一下 `notes2` 資料夾的內容吧! + hints: + - ➤ 使用 `ls notes2` 來查看 `notes2` 資料夾的內容 + exceptions: + - condition: + error: + - 'cp: omitting directory' + responses: + - type: narrative + content: + - 你忘記加上 `-r` 的參數了嗎? + - 請輸入 `cp -r notes notes2` 來複製 `notes` 資料夾到 `notes2` + + - id: ls-notes2 + requirements: + - cp-notes + task: 查看 `notes2` 資料夾的內容 + condition: + command: + - ^ls notes2$ + output: + - note.txt + responses: + - type: narrative + content: + - 你成功查看到 `notes2` 資料夾的內容了! + - 我們可以看到,整個 `notes` 資料夾包含裡面的檔案,都被複製到 `notes2` 資料夾了。 + - 那麼最後我們要來試試看,如果複製一個檔案到已經存在的檔案會發生什麼事。 + hints: + - ➤ 使用 `cp hello.txt world.txt` 來複製 `hello.txt` 到 `world.txt` + + - id: cp-overwrite + requirements: + - ls-notes2 + task: 複製 `hello.txt` 到 `world.txt` + condition: + command: + - ^cp hello.txt world.txt$ + responses: + - type: narrative + content: + - 你成功複製 `hello.txt` 到 `world.txt` 了! + - 我們打開來確認一下 `world.txt` 的內容吧! + hints: + - ➤ 使用 `cat world.txt` + + - id: END + requirements: + - cp-overwrite + task: 檢查 `world.txt` 的內容 + condition: + command: + - ^cat world.txt$ + output: + - Hello + responses: + - type: narrative + content: + - '`world.txt` 的內容變成 `Hello` 了!' + - 這是因為,當我們複製檔案時,如果目的檔案已經存在,那麼目的檔案的內容就會被覆蓋掉。 + - 所以在複製檔案的時候,要特別注意目的檔案是否已經存在,否則可能會不小心把資料弄丟。 + - 以上就是複製檔案的基本操作! diff --git a/quests/permission/home/file-r b/quests/permission/home/file-r new file mode 100644 index 0000000..88f87bd --- /dev/null +++ b/quests/permission/home/file-r @@ -0,0 +1 @@ +你有閱讀這個檔案的權限 \ No newline at end of file diff --git a/quests/permission/home/file-w b/quests/permission/home/file-w new file mode 100644 index 0000000..7a04f30 --- /dev/null +++ b/quests/permission/home/file-w @@ -0,0 +1,3 @@ +#!/bin/sh + +echo \ No newline at end of file diff --git a/quests/permission/home/file-x b/quests/permission/home/file-x new file mode 100644 index 0000000..14c4297 --- /dev/null +++ b/quests/permission/home/file-x @@ -0,0 +1,3 @@ +#!/bin/sh + +echo 你有執行這個檔案的權限 \ No newline at end of file diff --git a/quests/permission/zh.md b/quests/permission/zh.md new file mode 100644 index 0000000..f1cb390 --- /dev/null +++ b/quests/permission/zh.md @@ -0,0 +1,12 @@ +# 關卡名稱 + +## stage 名稱 {stage-id} + +> {speaker=角色名稱} +> 對話內容 + +### exception1 +content1 + +### exception2 +content2 \ No newline at end of file