title: 檔案路徑 instruction: | 在這個關卡中,你將會學到: 1. 絕對路徑和相對路徑 2. 如何使用 `pwd` 顯示目前的路徑 請輸入 `echo start` 來開始這一關。 requirements: - cast - explore stages: - id: warning-01 repeatable: true condition: command: - ' ' hints: - '!! 請勿使用全形空格 !!' - id: start task: 輸入 `echo start` 來開始教程 repeatable: false condition: output: - ^start$ responses: - content: - 在終端機中,並沒有圖形介面可以讓你查看資料夾的內容。 - 但是你可以透過 `ls` 指令來查看資料夾的內容。 - '`ls` 指令是 list 的縮寫,也就是列出檔案的意思。' - 在輸入 `ls` 指令後,終端機會輸出資料夾中包含的檔案和資料夾。 - 現在,請你試著輸入 `ls` 指令,查看資料夾中有什麼東西。 hints: - ➤ 輸入 `ls` 並查看資料夾的內容 - id: ls task: 查看資料夾中的檔案 requirements: - start condition: command: - ^ls$ responses: - content: - 你應該能看到資料夾中的內容了。 - 在畫面右邊的檔案樹也有了改變。 - 可以看出,在這個資料夾中包含了兩個資料夾,分別是 `folder1` 和 `folder2`。 - content: - 接下來,我要教你如何進入資料夾。 - '`cd` 指令是 change directory 的縮寫,也就是改變路徑的意思。' - 你可以通過輸入 `cd [資料夾名稱]` 來進入資料夾。 - 例如你要進入 `folder1` 資料夾,你可以輸入 - '`cd folder1`。' - 現在,請你試著進入 `folder1` 資料夾。 hints: - ➤ 輸入 `cd folder1` 來進入 `folder1` 資料夾 exceptions: - condition: not: pwd: - /home/commander hints: - ➤ 請先回到 `/home/commander/` 資料夾 - ➤ 輸入 `cd ~` 來返回 `/home/commander/` 資料夾 - condition: command: - ^[Ii]s$ hints: - '!! `ls` 的首字母是小寫的 `L`,不是 `I` !!' - id: cd-folder1 task: 進入 `folder1` 資料夾 requirements: - ls condition: pwd: - /home/commander/folder1 responses: - content: - 你成功的進入 `folder1` 資料夾了。 - 你可以發現指令提示符從原本的 - '`commander:~ $` 變成了' - '`commander:~/folder1 $` 。' - 這表示你現在正位在 `folder1` 資料夾中。 - 現在,請試著查看 `folder1` 資料夾的內容。 hints: - ➤ 輸入 `ls` 查看資料夾的內容 exceptions: - condition: pwd: - /home/commander hints: - ➤ 輸入 `cd folder1` 來進入 `folder1` 資料夾 - condition: not: pwd: - /home/commander hints: - ➤ 請先回到 `/home/commander/` 資料夾 - ➤ 輸入 `cd ~` 來返回 `/home/commander/` 資料夾 - id: ls-folder1 task: 查看 `folder1` 資料夾的內容 repeatable: false requirements: - cd-folder1 condition: pwd: - /home/commander/folder1 command: - ls responses: - type: narrative content: - 你現在可以看到 `folder1` 資料夾中有兩的檔案,分別是 `file1.txt` 跟 `file2.txt`。 - 現在我們可以離開 `folder1` 回到原本的資料夾了。 - 你可以使用 `cd ..` 回到上一層資料夾。 - 這裡的 `..` 代表的是上一層的資料夾。 hints: - 輸入 `cd ..` 回到上一層資料夾 - id: cd-.. task: 回到上一層資料夾 requirements: - ls-folder1 condition: pwd: - /home/commander responses: - type: narrative content: - 你成功的回到上一層資料夾了。 - 現在,請你剛才所學的指令,進入 `folder2` 資料夾,檢查 `folder2` 資料夾的內容,最後回到這個資料夾。 hints: - ➤ 使用 `cd` 指令進出資料夾 - ➤ 使用 `ls` 指令查看資料夾的內容 - id: cd-folder2 task: 進入 `folder2` 資料夾 requirements: - cd-.. condition: pwd: - /home/commander/folder2 responses: - content: - 你成功的進入 `folder2` 資料夾了。 - 現在,請你查看 `folder2` 資料夾的內容。 hints: - ➤ 使用 `ls` 查看資料夾的內容 - id: ls-folder2 task: 查看 `folder2` 資料夾的內容 requirements: - cd-folder2 condition: pwd: - /home/commander/folder2 command: - ls responses: - type: narrative content: - 你看到了 `folder2` 資料夾中的檔案,分別是 `file3.txt` 跟 `file4.txt`。 - 現在你可以離開 `folder2` 回到原本的資料夾了。 hints: - ➤ 使用 `cd ..` 回到上一層資料夾 - id: END task: 回到原本的資料夾 requirements: - ls-folder2 condition: pwd: - /home/commander responses: - type: narrative content: - 你成功的回到原本的資料夾了。 - 恭喜你學會了 `ls` 和 `cd` 指令的用法。 hints: - ➤ 使用 `cd` 指令進出資料夾 - ➤ 使用 `ls` 指令查看資料夾的內容