Linux 入門
介紹
Linux 是一個免費的開源作業系統,目前被全世界廣泛應用於各種伺服器,工作站,及個人電腦。Linux 作業系統發展至今,已經衍生出許多分支,在世界上有許多不同的Linux發行版,比較廣為人知的發行版有:
- (Red Hat系)
- Red Hat Enterprise Linux (Fedora的商業版)
- CentOS
- Fedora (CentOS相關)
- openSUSE
- (Debian系)
- Debian
- Ubuntu (從Debian衍生)
- Elementary OS (從Ubuntu衍生,適合做個人電腦用)
- Arch Linux
- Clear Linux OS (新,Intel主導)
這些Linux發行版都是建立於GNU/Linux 發行版之上,再依據各家對其進行客製化,所以基本上這些發行版的底層及基本指令都是可以互通的。相較於Windows系統,Linux十分依賴使用Terminal(類似Windows的CMD)進行操作,而非使用圖形介面。這個差異使得許多長期使用Windows的用戶感到很難上手,不過對於使用Linux當作伺服器,使用指令介面可以帶來許多好處,也十分方便。
- 可以透過SSH連線操作,不須透過額外安裝遠端桌面軟體,安全性大幅提昇。
- 無須執行圖形介面,省下許多不必要的效能消耗。
- 許多伺服器軟體因為市場需求,皆對於Linux有著很好的支援,有許多方便的指令。
- 可以把指令建置成腳本,讓其自動運行,這是圖形化操作無法達成的。
操作
基本上Linux的所有操作都可以使用指定來達成,這些指令都是寫好的應用程式,放在預設的指定位置,當我們下這些指令時,實際上系統是去執行這些應用程式,來達到我們要的功能。下面我們依照功能來分類介紹一些常用的指令。
1. 檔案操作
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 軟連結 (softlink 或 symbolic link):指向另一支檔案或目錄的捷徑檔
- 硬連結 (hardlink):指向 inode index,無法指向目錄
- Hardlink 無法跨檔案系統使用 (因 inode 不同)
- Hardlink 會增加 link count
- 一支檔案的檔名就是 hardlink 的例子
2. 輸入與輸出重新導向
- Shell 的 file descriptor (fd) 通常有 10 個,以下是常用的 3 個標準輸出
- fd = 0 (/dev/stdin)
- fd = 1 (/dev/stdout)
- fd = 2 (/dev/stderr)
- 使用 < 改變讀入的資料通道 (stdin)
- 從指定的檔案中讀入,< 的預設值為 0,所以 < 與 0< 一樣
- 使用 >, >> (附加) 改變輸出的資料通道 (stdout, stderr)
- 輸出到指定的檔案中,> 的預設值為 1,所以 > 與 1> 一樣
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
3. Pipe 與 Tee
- 用 pipe ( | ) 連接一系列指令的執行
- 一個指令執行後的輸出會通過 pipe 傳給第二個指令當作輸入,而第二個指令的輸出又會傳給第三個指令作為輸入,依此類推
- 範例
$ ls / | sort -r
$ du | sort –nr
$ ls –lt | head
- 使用 Tee 在 pipe 同時,又進行重導向
- 範例
$ du -d1 -h | tee unsorted.txt | sort -nr
$ more unsorted.txt
$ du -d1 -h | tee 1.txt 2.txt 3.txt | sort -nr
4. 打包檔案
- 使用 tar 工具將檔案與目錄打包成為單一歸檔 (archive, 未壓縮, 或稱為 tar ball)
- 打包參數 -cvf (c: 建立新歸檔, v: 顯示詳情, f: 指定檔名)
- 拆封參數 -xvf (x: 取出歸檔, v: 顯示詳情, f: 指定檔名)
- tar 可配合壓縮工具,打包兼壓縮歸檔
- 壓縮參數 -czvf (gzip), -cjvf (bz2)
- 解壓參數 -xzvf (gzip), -xjvf (bz2)
- 解開 tar ball 的指令最後可以加上 -C path 來指定解出檔案存放的位置
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
5. echo, cat, more, less, wc, head, tail 與 sort
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
6. grep, diff, find 與 whereis
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
7. du, df, lsblk, free 與 fdisk
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
8. file, wget, curl, ifconfig, ping, pwd 與 reboot
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
9. 帳戶管理
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
10. /etc/passwd, /etc/shadow 及 /etc/group
- 帳號與群組以 UID/GID 數字紀錄
- UID/GID 對應檔在 /etc/passwd 及 /etc/group
- UID 0 為 root
- 非 0 為一般帳號 (1~999 為系統帳號,大於 1000 為可登入帳號)
- /etc/passwd
- 名稱:密碼(x):UID:GID:全名:家目錄:Shell
- 帳號密碼在 /etc/shadow 檔 (僅 root 可更動該檔)
- 名稱:加密密碼:更動日期:最小可變動日:最大需變動日:過期前警告日數:失效天數:帳號失效日:保留
11. 觀察檔案權限
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
12. 檔案權限管理
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
13. 查看處理程序
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →