Files
linux-odyssey/quests/path/game.yml
T
2023-11-24 12:56:57 +08:00

180 lines
5.8 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
title: 檔案路徑
instruction: |
在這個關卡中,你將會學到:
1. 絕對路徑和相對路徑
2. 如何使用 `pwd` 顯示目前的路徑
準備好就輸入 `echo start` 開始吧!
requirements:
- cast
- explore
stages:
- id: warning-01
repeatable: true
condition:
command:
- ' '
hints:
- '!! 請勿使用全形空格 !!'
- id: start
task: 輸入 `echo start` 來開始教程
condition:
output:
- ^start$
responses:
- content:
- 在 Linux 系統中,每個資料夾和檔案都有獨一無二的路徑。
- 而路徑又分為相對路徑和絕對路徑。
- 相對路徑是從目前所在的資料夾開始的路徑,而絕對路徑則是從根目錄開始的路徑。
- 請你先用 `ls` 指令查看這個資料夾中的檔案。
- id: ls
task: 查看資料夾中的檔案
requirements:
- start
condition:
pwd:
- ^/home/commander$
command:
- ^ls$
responses:
- content:
- 現在你使用 `cd` 指令進入 `folder1` 資料夾。
- id: cd-folder1
task: 進入 `folder1` 資料夾
requirements:
- ls
condition:
pwd:
- ^/home/commander/folder1$
responses:
- content:
- 你進入了 `folder1` 資料夾。
- 在進入 `folder1` 資料夾時,使用的 `cd folder1` 中的 `folder1` 就是相對路徑。
- 相同的道理 `cd ..` 中的 `..` 也是相對路徑。
- 相對路徑可以不只有一層資料夾。
- 例如:現在想要進入 `folder2` 資料夾的話,可以使用 `cd ..` 回到上一層資料夾,再使用 `cd folder2` 進入 `folder2` 資料夾。
- 然而,你也可以用 `/` 將 `..` 和 `folder2` 依序連接起來,使用 `cd ../folder2` 來一次進入 `folder2` 資料夾。
- 現在試著用這個方式進入 `folder2` 資料夾看看吧。
hints:
- ➤ 請輸入 `cd ../folder2` 來進入 `folder2` 資料夾。
- id: cd-folder2
task: 進入 `folder2` 資料夾
requirements:
- cd-folder1
condition:
pwd:
- ^/home/commander/folder2$
exceptions:
- condition:
not:
pwd:
- ^/home/commander/folder1$
responses:
- type: narrative
content:
- 請先回到 `folder1` 資料夾,並用指定的方式進入 `folder2` 資料夾。
responses:
- content:
- 你成功的用相對路徑進入了 `folder2` 資料夾。
- 而你也能夠在 `ls` 後加上相對路徑來查看其他資料夾的內容。
- 例如:現在你想要查看 `folder1` 資料夾中有哪些檔案,你可以使用 `ls ../folder1` 來查看。
- 試著用這個方式查看 `folder1` 資料夾中的檔案吧。
hints:
- ➤ 請輸入 `ls ../folder1` 來查看 `folder1` 資料夾中的檔案。
- id: ls-folder1
task: 查看 `folder1` 資料夾中的檔案
requirements:
- cd-folder2
condition:
output:
- file1.txt
exceptions:
- condition:
not:
pwd:
- ^/home/commander/folder2$
responses:
- type: narrative
content:
- 進到 `folder1` 資料夾並用 `ls` 查看內容。
responses:
- content:
- 很好,你現在知道如何運用相對路徑了。
- 接下來要介紹的是絕對路徑。
- 絕對路徑是從根目錄開始的路徑,根目錄是位於檔案樹的最上層的資料夾。
- 你可以使用 `pwd` 來查看目前所在的絕對路徑。
- '`pwd` 的意思是 `print working directory`,也就是顯示目前所在的路徑。'
- 現在請你使用 `pwd` 來查看目前所在的絕對路徑。
hints:
- ➤ 輸入 `pwd` 查看目前所在的絕對路徑
- id: pwd
task: 查看目前所在的絕對路徑
requirements:
- ls-folder1
condition:
pwd:
- ^/home/commander/folder2$
command:
- ^pwd$
exceptions:
- condition:
not:
pwd:
- ^/home/commander/folder2$
responses:
- type: narrative
content:
- 請先回到 `folder2` 資料夾,並用 `pwd` 來查看目前所在的絕對路徑
responses:
- content:
- 你可以看到你現在的絕對路徑是 `/home/commander/folder2`。
- 而絕對路徑其實也顯示在你的命令提示符中。
- '`commander:~/folder2 $` 中的 `~/folder2` 就是你的絕對路徑。'
- 而 `~` 則是 `/home/commander` 這個絕對路徑的縮寫,又稱為家目錄,你每次遊戲都會從這裡開始。
- '`ls` 和 `cd` 指令也可以使用絕對路徑。'
- 例如:你可以使用 `ls ~` 來查看家目錄的內容,或使用 `cd ~` 來回到家目錄。
- 現在請你使用 `ls ~` 來查看家目錄的內容。
hints:
- ➤ 輸入 `ls ~` 來查看家目錄的內容
- id: ls-~
task: 查看家目錄的內容
requirements:
- pwd
condition:
command:
- ^ls ~$
responses:
- content:
- 現在請使用 `cd ~` 回到家目錄。
hints:
- ➤ 輸入 `cd ~` 來回到家目錄
- id: END
task: 回到家目錄
requirements:
- ls-~
condition:
command:
- ^cd ~$
exceptions:
- condition:
pwd:
- ^/home/commander$
responses:
- type: narrative
content:
- 請使用 `cd ~` 回到家目錄
responses:
- content:
- 你回到家目錄了。
- 恭喜!現在你已經知道如何運用絕對路徑和相對路徑,以及查看目前所在的絕對路徑了。