學會用終端機跟電腦說話,這是所有開發工作的起點。
所有開發工具(Git、Node.js、AI CLI)都在終端機裡運作。學好它,才能用好所有工具。
Command ⌘ + Space 開啟 SpotlightTerminal或是:Finder → 應用程式 → 工具程式 → 終端機
Win + X或是:開始選單 → 搜尋 PowerShell
Windows 11 建議安裝 Windows Terminal(Microsoft Store 免費)
開啟後你會看到這行,這是在等你輸入指令:
ian@MacBook ~ %
ian — 你的使用者名稱~ — 目前所在位置(家目錄)% — 提示符號,表示可以輸入了PS C:\Users\ian>
PS — PowerShell 縮寫C:\Users\ian — 目前所在位置> — 提示符號路徑就是一個檔案或資料夾在電腦裡的「地址」。
| 符號 | 意思 | macOS 範例 |
|---|---|---|
/ | 根目錄(最上層) | / |
~ | 家目錄 | /Users/ian |
. | 目前所在目錄 | ./Documents |
.. | 上一層目錄 | ../Desktop |
Windows 路徑用反斜線 \,例如 C:\Users\ian。PowerShell 也接受 /。
pwd — 我在哪裡?Print Working Directory — 顯示你目前所在的路徑。
~ % pwd
/Users/ian
PS C:\Users\ian> pwd
Path
----
C:\Users\ian
迷路了嗎?隨時輸入 pwd 確認自己在哪裡。
ls — 這裡有什麼?List — 列出目前資料夾裡的所有檔案與資料夾。
~ % ls
Desktop Documents Downloads
~ % ls -la # 詳細資訊 + 隱藏檔
drwxr-x--- ian Desktop
-rw-r--r-- ian hello.txt
ls -l 詳細資訊 | ls -a 含隱藏檔 | ls -la 全部PS C:\Users\ian> ls
Mode LastWriteTime Name
---- ------------- ----
d---- 5/5/2026 Desktop
d---- 5/5/2026 Documents
ls、dir、Get-ChildItem 在 PowerShell 裡功能相同。
cd — 移動位置Change Directory — 切換到不同的資料夾。
# 進入 Documents 資料夾
cd Documents
# 回到上一層
cd ..
# 回到家目錄
cd ~
# 直接跳到指定路徑
cd ~/Documents/my-project
輸入資料夾名稱的前幾個字後,按 Tab 自動補全!
mkdir — 建立資料夾Make Directory — 建立一個新的資料夾。
# 建立資料夾
mkdir project
# 一次建立多層資料夾
mkdir -p project/src/components # macOS
mkdir project\src\components # Windows
macOS 需要加 -p 才能一次建立多層;Windows 的 mkdir 預設就支援。
touch / ni — 建立空白檔案# 建立一個空白的 hello.txt
touch hello.txt
# 一次建立多個檔案
touch index.html style.css app.js
# ni 是 New-Item 的縮寫
ni hello.txt
# 完整寫法
New-Item hello.txt
Windows PowerShell 沒有 touch,要用 ni 或 New-Item。
cat — 查看檔案內容不用開啟編輯器,直接在終端機顯示檔案的文字內容。
cat hello.txt
# Hello, World!
# This is my first file.
Mac & Win 相同指令,兩個系統都適用。
nano / notepad — 編輯文字檔nano hello.txt
Ctrl + O → 儲存Ctrl + X → 離開有安裝 VS Code 的話:code hello.txt
notepad hello.txt # 記事本
code hello.txt # VS Code(需先安裝)
rm — 刪除終端機刪除的檔案不會進回收桶,刪了就真的消失了!
# 刪除一個檔案
rm hello.txt
# 刪除一個資料夾(-r 遞迴刪除)
rm -r project/ # macOS
rm -r project # Windows
# macOS 強制刪除(不詢問確認)
rm -rf project/
cp 複製 / mv 移動# 複製檔案
cp hello.txt backup.txt
# 複製資料夾
cp -r project/ backup/ # Mac
cp -r project backup # Win
# 重新命名
mv hello.txt greet.txt
# 移動到資料夾
mv greet.txt Documents/
Mac & Win 語法相同。
| 指令 | 功能 | 差異 |
|---|---|---|
whoami | 顯示目前使用者 | 同 |
clear / cls | 清除畫面 | Mac: clear,Win: cls |
echo "文字" | 印出文字 | 同 |
echo "文字" > 檔案 | 寫入檔案 | 同 |
輸入前幾個字後按 Tab,終端機自動補全。按兩下列出所有選項。
按 ↑ 叫出上一條指令,不需要重新打。
程式卡住時,按 Ctrl + C 強制中斷。
pwd 確認位置cd ~ 回到家目錄mkdir my-project 建立資料夾cd my-project 進入資料夾touch index.html(Mac)或 ni index.html(Win)echo "Hello" > index.html 寫入內容cat index.html 確認內容你已經學會了終端機的基本操作。
接下來學會用 AI 幫你寫程式。