Terminal、Shell、Bash — 它們各自是什麼?
Terminal
那個「黑色視窗」程式(Terminal.app、iTerm、GNOME Terminal、Windows Terminal、PuTTY),負責顯示文字與接收鍵盤輸入。它是 外殼,不是真正在執行指令的人。
The "black window" program (Terminal.app, iTerm, GNOME Terminal, Windows Terminal, PuTTY). It just displays text and receives keystrokes — it's the shell of the shell, not the executor.
Shell
真正讀懂並執行指令的程式:把你輸入的 ls -lh 解析成「呼叫 /usr/bin/ls,帶 -lh 參數」。常見有 bash、zsh、fish。
The actual program that parses and runs your commands: it turns ls -lh into "call /usr/bin/ls with -lh". Common shells: bash, zsh, fish.
Bash
最普及的 shell,幾乎所有 Linux 教程預設都用 bash。本課程的所有腳本都用 bash 撰寫。
The most widespread shell — every Linux tutorial defaults to bash. All scripts in this course are written in bash.
想知道你現在用哪個 shell?輸入 echo $SHELL 或 ps -p $$。如果輸出是 /bin/bash 或 /usr/bin/bash,你就在 bash 裡。
Wondering which shell you're in? Run echo $SHELL or ps -p $$. If you see /bin/bash or /usr/bin/bash, you're in bash.
Linux 檔案系統的全貌
Linux 的所有東西都掛在一棵「單一根目錄樹」上,最頂端是 /(不是 C: D: 那種磁碟代號)。常見路徑如下:
Everything in Linux hangs from a single root tree starting at / (no C:, D: drive letters). Common paths:
/ # 根目錄 ├── home/ # 一般使用者家目錄都在這 │ └── charlene/ # 你的家目錄 = ~ = $HOME │ └── project/ # 工作中的 NGS 專案 ├── usr/bin/ # 安裝的指令會在這 (ls, samtools …) ├── etc/ # 系統設定檔 ├── tmp/ # 臨時檔,重開機會清空 ├── opt/ data/ # 自行掛載的大型儲存常放這 └── mnt/ # 暫掛 USB / 網路硬碟
在 HPC 或實驗室伺服器上,重要 NGS 資料常放在 /data、/scratch、/work、/home、/share 等不同位置。配額(quota)、I/O 速度、備份政策都不一樣,記得先問你的系統管理員。
On HPC or lab servers, NGS data may live in /data, /scratch, /work, /home, /share — each with different quotas, I/O speed and backup policies. Ask your sysadmin first.
絕對路徑 vs 相對路徑
| 路徑類型 | 特徵 | 範例 |
|---|---|---|
| 絕對路徑 | 一定以 / 開頭 | /home/charlene/project/raw_data/sampleA_R1.fastq.gz |
| 相對路徑 | 不以 / 開頭 | raw_data/sampleA_R1.fastq.gz |
~ |
自己的 home 目錄 | ~/project/raw_data |
. | 目前資料夾 | ./run_fastqc.sh |
.. | 上一層資料夾 | cd ../reference |
實務原則:寫 script、log、README 時建議用絕對路徑,避免「在不同資料夾下執行就會壞掉」;互動操作時則用相對路徑比較快。
Rule of thumb: use absolute paths in scripts, logs and README files — they survive being run from any directory. Use relative paths for fast interactive work.
導航三劍客:pwd / cd / ls
一個 Linux 必學的鍵:Tab
Tab 自動補全是 Linux 上最重要的省時技巧。輸入指令或檔名前幾個字,按一下 Tab,shell 會幫你補完到唯一可能的選項;按兩下會列出所有可能的選項。
- 輸入
cd raw_d→ 按 Tab → 自動變成cd raw_data/ - 輸入
ls samp→ 按 Tab Tab → 列出 sampleA、sampleB... - 檔名超長(如
SRR12345678_1.fastq.gz),Tab 補全可避免打錯字
Tab completion is the single most important time-saver in Linux. Type a few characters and press Tab — the shell completes the unique match; press it twice to list candidates.
- Type
cd raw_d→ Tab → becomescd raw_data/ - Type
ls samp→ Tab Tab → lists sampleA, sampleB… - For long filenames like
SRR12345678_1.fastq.gz, Tab eliminates typos.
↑ ↓ 歷史紀錄
按 ↑/↓ 翻閱之前輸入過的指令;按 Ctrl+R 反向搜尋(輸入幾個字就能找到一週前打過的命令)。
Press ↑/↓ to scroll through earlier commands; Ctrl+R reverse-search lets you find a command from last week with a few keystrokes.
Ctrl + C / D / L / U
Ctrl+C=中斷指令,Ctrl+D=結束輸入/登出,Ctrl+L=清螢幕(同 clear),Ctrl+U=清掉整行輸入。
Ctrl+C=interrupt, Ctrl+D=EOF/logout, Ctrl+L=clear screen (= clear), Ctrl+U=clear current input line.
動手練習:在 NGS 專案中走動
下方終端機已預先載入一個 NGS 專案。試著完成以下任務:
- 輸入
pwd看看目前在哪 - 輸入
ls看看現在資料夾有什麼 - 輸入
cd raw_data進入 raw_data - 再
ls -lh看詳細列表 cd ..回上層;cd ~回家目錄
The simulator below has a pre-loaded NGS project. Try:
pwdto see where you arelsto see what's aroundcd raw_datato enter raw_datals -lhfor the detailed listingcd ..to go up;cd ~to go home
📝 自我檢測
1. 下列哪一個是絕對路徑?
1. Which is an absolute path?
2. 想從 ~/project/raw_data 跳到 ~/project,應該下哪個指令?
2. From ~/project/raw_data, which command moves you to ~/project?
3. 想看 raw_data 裡每個 fastq.gz 的檔案大小(顯示為 KB/MB/GB),最直接的指令是?
3. To see each fastq.gz size in raw_data (in KB/MB/GB), the most direct command is?
4. 為什麼老手都狂按 Tab?
4. Why do experienced users hammer Tab?