# Basic Linux ### Yu-Chi Lai --- # Intro ---- ## Linux 介紹 + 由 Linus Torvalds 於 1991 年首次發布 + 自由且開放的類 Unix 系統 + 高安全性、高穩定性、高移植性 + 常用於伺服器 ---- ## 特色 + 通常無 GUI 介面,效能高 (硬體需求、耗的資源少) (? + **免費** + 有超多發行版本 ( e.g: Ubuntu、Debian、CentOS、PopOS、Mangaro... etc),自由度、架構開放穩定 ---- | Linux 的 Logo | Linus Torvald | | -------- | -------- | | ![](https://i.imgur.com/4YNpWrQ.png =350x350) | ![](https://i.imgur.com/2azTqFs.png =500x300) | ---- ## 環境設定 (方法很多) + [WSL](https://hackmd.io/@billsun/BJByCIUHf) + 到 [官網](https://ubuntu.com/download/desktop/thank-you?version=22.04.1&architecture=amd64) 下載映像檔,以 USB & Rufus安裝 + Virtual Machine --- # Commands ---- ## Command usage ```bash! $ command(指令) [Options](可選選項) Argument(必要參數) # e.g. $ ls -al ./ ``` ---- ### ls [DIR|FILE] + 列出資訊,未指定為當前資料夾 + -a: 列出全部 (包含隱藏檔案) + -l: 詳細資訊 ```bash! $ ls -a $ ls -l ``` ---- ### Tab auto complete + tab 鍵可以自動補全 + 檔案名稱 + 資料夾名稱 + 指令 ---- ### clear + 清空當前 Terminal 的文字 + 你也可以按 Ctrl+L ```bash! $ clear ``` ---- ### cd [DIR] + 切換資料夾 + ./: 當前資料夾 + ../: 母資料夾 + ~: 家目錄 (/home/<USER>) ```bash! expectlai@linux: ~/INFOR35th$ ls # Images Lectures 225 expectlai@linux: ~/INFOR35th$ cd Lectures expectlai@linux: ~/INFOR35th/Lectures$ ``` ---- ### pwd + 顯示當前路徑 (存於 `env` 中) ```bash! expectlai@linux: ~/INFOR35th$ pwd /home/expectlai/INFOR35th ``` ---- ### mkdir [DIR] + 創建新資料夾 + `-p`: 創建過程有不存在的資料夾,會同步創建 ```bash! $ mkdir programing $ mkdir test/dir1 # mkdir: can not create directory, ... $ mkdir -p test/dir1 ``` ---- ### cat [FILE] & FILE [file] + cat 可以抓取檔案內容 + file 可以用 File Header 查看檔案類型 ```bash! $ cat orz.txt # OOO,我好崇拜你,我是你的粉絲! $ file orz.txt # orz.txt: ASCII Text ``` ---- ### strings [FILE] + 預設抓取 4 個以上連續可視字元為一組顯示,不包含 (`\n`,`\t`,`\r`) + `-n`: 指定最短連續可視字元長度 ```bash! $ strings tmp # Hello # world # Goodbye! ``` ---- ### man help 查看指令手冊 ```bash! $ man ls ``` ![](https://i.imgur.com/aUc3KL1.png =750x430) ---- ### apt [OPTIONS] <APT> 套件管理工具 + install: 下載套件 + upgrade: 更新特定套件 + update: 更新下載資訊 ![](https://i.imgur.com/Hg4B2iu.png) ---- ### sudo [CMD] + 使用最高權限執行指令 + su: 切換至最高權限 (通常為 root) ![](https://i.imgur.com/Phb1BjG.png) ---- ### Authority ![](https://i.imgur.com/FouCh3H.png) ---- ### Authority code ![](https://i.imgur.com/9SrQEUQ.png) ---- ### chmod [DIR|FILE] + 修改檔案或是資料夾權限 + +-: 新增或移除權限 + u: 針對當前使用者修改權限 ![](https://i.imgur.com/PlyGrDE.png) ---- ### rm [DIR|FILE] + 移除檔案或資料夾 + `-r`: 移除資料夾 + `-f`: 強制移除 ![](https://i.imgur.com/7iuHbxw.png) ---- ### mv [DIR|FILE] [DIR|FILE] 移動或是重新命名 ![](https://i.imgur.com/yYiE300.png) ---- ### cp [DIR|FILE] [DIR|FILE] + 複製檔案或資料夾 + `-r`: 複製資料夾 ![](https://i.imgur.com/ckCngzv.png) ---- ### grep [STR|REGEX] [FILE] & history grep + 搜尋檔案中,符合格式的字串 + `-i`: 忽略大小寫 + `-o`: 僅輸出符合的字串 + `-P`: 使用 Regex history + 顯示指令歷史紀錄 + `-c`: 清空歷史紀錄 ---- ![](https://i.imgur.com/3YtvZMV.png) ---- ### data stream Unix 3 data stream | stdin | 標準輸入 | code: 0 | | -------- | -------- | -------- | | stdout | 標準輸出 | code: 1 | | stderr | 標準錯誤輸出 | code: 2 | ---- ### data redirect + \>: 資料導入至檔 + \>>: 資料串接至檔案內容後 + 2>&1: stderr 導向至 stdout ![](https://i.imgur.com/4uoKYmc.png) ---- ### pipeline | + 傳遞前一個指令的 stdout 至後方的 stdin ![](https://i.imgur.com/I8sxUHU.png) ---- ### Previous command + 使用上下鍵切換至使用過的指令 + `!!`: 輸出、執行最後一次執行的指令 --- # Practice ---- 練習 + [picoCTF 的 General skills](https://play.picoctf.org/practice?category=5&page=1) + 撰寫 [shell script](https://blog.techbridge.cc/2019/11/15/linux-shell-script-tutorial/) + 把 Linux 的課程整理成 .md 文件,丟上 Github ---- # The end #### Thanks for your listening!
{"metaMigratedAt":"2023-06-17T13:21:39.288Z","metaMigratedFrom":"YAML","title":"建中資訊 Basic Linux","breaks":true,"slideOptions":"{\"transition\":\"slide\",\"theme\":\"black\"}","contributors":"[{\"id\":\"2679575e-9566-4845-9f09-0190787b1580\",\"add\":3923,\"del\":186}]"}
    396 views