kyle shanks
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    2
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: 'Linux 目錄、指令基礎' disqus: kyleAlien --- Linux 目錄、令基礎 === ## OverView of Content 如有引用參考請詳註出處,感謝 :smile_cat: [TOC] ## Linux 介紹 Linux 為類 Unix 操作系統,其實 **Linux 為一個內核**,而它的拓展才是系統 (Ubuntu / red hat... 等等),但大部份人會直接稱為 Linux 為系統 ### Unbuntu * [**Ubuntu Download**](http://www.ubuntu-tw.org/modules/tinyd0/) > ![](https://i.imgur.com/hLKirKV.png) * Ubuntu 取名規則 `ubuntu- 18.0404-desktop-amd64.iso` > 18 年 0404 月份日期 版本有分為桌面板(desktop) / 服務企版本(Server) 版本發布頻率,一年兩次 > 主版本號(年份),**單數年號為短期支援版本,雙數年號為長期支援版本 (LTS)** > > 父版本號(月份),**++xx.04 為該年度穩定板++,xx.10 為年度測試板** ## 基礎指令 ### 超級用戶 * 功能像是 window 中,++**以系統管理員執行**++,提高使用權限 * 目前權限可經由符號判,`$`(使者)`#`(管理者) | 指令 | 功能 | | -------- | -------- | | sudo + 指令 | 提權一次(其實是 ++固定時間內++ 的提權) | | sudo su | ++持續提權++至退出 | | exit | 退出超級用戶 | | whoami | 查看當前登錄的用戶名稱 | :::info * su root 指令? **++Ubuntu Root 如果沒有設置時是隨機的++**(每次開機都有新的密碼),可就由 sudo passwd 設定密碼,**之後就可以使用 su root 指令** ::: ### 輸入常用指令 * 由於在**輸入指令時手很少離開鍵盤**(停留在字母區,不包括數字、上下左右鍵),以下以 **輸入指令** 時常用的命令來做介紹 | 指令 | 功能 | 記憶方法 | | -------- | -------- | -------- | | ctrl + p | 上一個指令 | previous | | ctrl + n | 下一個指令 | next | | ctrl + b | 光標退回(向左) | backward | | ctrl + f | 光標向前(向右) | forward | | ctrl + a | 光標移至頭部 | head | | ctrl + e | 光標移至尾端 | end | | ctrl + d | **刪除**光標**後** | delete | | ctrl + h | **刪除**光標**前** (不包括當前光標) | Backspace | | ctrl + u | **刪除**光標**前==所有==** | | | ctrl + j | **輸入指令** | Enter | ### 操控常用指令 * 當指令不知如何使用時,可用 `man + 指令`,查詢出該命令如何使用 | 指令 | 功能 | 補充 | 範例 | | -------- | -------- | -------- | -------- | | tree | 以樹狀顯示目錄,Window 中也有 | **該指令不包含於原本的功能中**,必須透過 apt install tree | tree /bin | | ls | 查詢指定目錄下的所有文件 & 目錄訊息,常用 -a(all) | **就算是空目錄也有,當前目錄`.`、父目錄`..`**、**==隱藏文件以 `.` 開頭==,如果沒指定代表當前目錄** | 指定 \bin 目錄 ls -la \bin | | cd | 同 window,**進入指定目錄,可指定相對路進、絕對路徑** | 以`.`代表當前目錄、`..`代表上層目錄,cd \ 進入根目錄、cd ~ 進入使用者目錄 | cd \home -> cd .\aliens | | pwd | 顯示當前目錄 | | cd \home\aliens -> pwd | | mkdir | 創見目錄,**-p 可創建++巢狀目錄++** | 該目錄若已有不會創建 | make -p ./aa/bb/cc | | rmdir | **移除 ++空目錄++** | **只能移出空目錄,很少使用**| rmdir ./aa/bb/cc | | touch | **==創建文件==** | | touch ./aa/bb/cc.txt | | cp | 複製文件 & 目錄 | **文件不存在則創建,文件存在則覆蓋,如果++巢狀目錄要用 -r 複製++** | cp aa.txt ff.txt | | mv | 移動檔案 | | mv xxv.txt ./aa/bb | | history | 指令輸入歷史 | | history | | which | 查詢指令集位置,**在 PATH 變量環境中** | **cd 是 bash 內建,所以查不到** | history | | clear | 清除螢幕上的指令 | | clear | ### 查看文件 * 有四種查看方式,各有特色 | 指令 | 功能 | 補充 | | -------- | -------- | -------- | | cat + 文件名 | 將文件一次行輸出的螢幕 | 文件**太長則無法全部輸出** | | more + 文件名 | 一次一個螢幕輸出,Enter 換下一行,空格下一頁,q 退出 | **只能往下閱讀** | | less + 文件名 | 操作如 more,**但是可上 (ctrl+p) 下 (ctrl+n) 閱讀**| less cc.txt | | head + 文件名 | 從頭查看至第幾行,-(行數) | head -10 cc.txt | | tail + 文件名 | 與 head 相反,從尾查看至前幾行,-(行數) | tail -10 cc.txt | > ![](https://i.imgur.com/PfxxUMn.png) ### R/W 文件 -vim 指令 * vim 指令可以直接對文件做出編譯,[**詳細可參考**](http://www.vixual.net/blog/archives/234) | 指令 | 功能 | | -------- | -------- | | i | 從頭開始輸入 | * 以下在對 vim 輸入完文檔後,**按下 Esc 就可以到指令操作,這時下面的指令就是對這個文件的==保存方式==** | 指令 | 功能 | | -------- | -------- | | :q | **沒修改文件 & 不儲存**的離開 | | :q! | **++有++修改文件 & 不儲存**的離開 | | :w | 只儲存 | | :wq | 儲存 & 離開 | | :w + 檔案名稱 | 令存新檔 | | :x | 功能如同 :wq,儲存 & 離開 | ### echo 指令 | 指令 | 功能 | | -------- | -------- | | echo | 輸出指令在螢幕上,也可輸出檔案 | | > | 輸出檔案 | | >> | 接續輸出檔案,類似 append,但是會換行 | | | | 1. echo 可以 **輸出\覆蓋** 檔案 (**==>==**),也可以繼續 **編譯檔**案 內容 (**==>>==**) ```shell= // 創建檔案 echo "Hi, Linux!" > hi.txt // 覆蓋檔案 echo "Hi, Linux! I'm Kyle" > hi.txt // 換行,新增檔案內容 echo "Hi, Linux! I'm Alien" >> hi.txt ``` > ![](https://i.imgur.com/9ncO97M.png) ### 軟/硬連結 * 類似於一種**捷徑的概念** | 連接類型 | 說明 | 大小 | 注意 | 其他 | | -------- | -------- | -------- | -------- | -------- | | 軟 (Symbolic) | 可創造目錄軟連結 | 副本的形式 | 有主從關係,若主被刪除,從也無法訪問到 | 代表的**就像是 window 中的捷徑** (類似指標,指向該目標檔案,本身就是指針的大小) | | 硬 | ++不可++創造目錄軟連結,**並且同步原文件更新** | 原文件大小 + 路徑的總字節數 | **原文件必須是++絕對路徑++** | 在同一系統中才能創建 | 1. 初始化檔案,並創建軟、硬連結 ```shell= # 創建一個檔案 touch file1 # 預設 ++強連結++ ln flie1 file2 # -s 就是 symbolic (軟連結) ln -s file1 file3 # 查看目錄屬性 ls -lai ``` > ![](https://i.imgur.com/o56n0W8.png) 2. 對 file1 寫入數據,查看 file2、file3 的檔案大小 > ![](https://i.imgur.com/217yZB4.png) 3. 刪除 file1,查看 file2、file3 的檔案,會發現軟連結失敗 > ![](https://i.imgur.com/NLDqnpG.png) ## Linux 目錄 & 文件 目錄詳細並標準的要查詢 [**Filesystem Hierarchy Stander(FHS) for Linux**](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard) 這有 Linux 目錄下所有的檔案介紹 ### 文件顏色 * 在指令輸入時常常可以看到不同顏色的指令,而不同顏色代表了不同的文件意義 | 顏色 | 意義 | 其他 | | -------- | -------- | -------- | | <font color="#fff">==白色==</font> | 普通文件 | | | <font color="#00f">籃色</font> | **目錄** | | | <font color="#0f0">綠色</font> | **可執行文件** | | | <font color="#f00">紅色</font> | **++壓縮文件++** | | | <font color="#00FFFF">青色</font> | **連結文件** | | | <font color="#ff0">==黃色==</font> | **設備文件** | 在目錄 dev 下有很多 | | <font color="#808080">灰色</font> | **其他** | | ### 目錄判斷 | 目錄 | 意義 | 其他 | | -------- | -------- | -------- | | 絕對路徑 | 需要全路徑名,從根目錄開始 `/../..` | | | 相對路徑 | `.` 代表目前路徑,`..` 代表上層路徑,切換兩個目錄時可以使用 `cd -` | cd - 切換 ![](https://i.imgur.com/AqG1e1b.png) | :::info 指令行解釋 : `aliens@aliens-B4-WIFI:/$` 1. aliens:用戶名 2. @:在 / at 的意思 3. aliens-B4-WIFI:主機名稱 4. ~:當前所在的路徑,可使用 pwd 命令查詢 5. #/$:當前用戶權限 ::: ### 資料夾介紹 * 了解 Linux 目錄對於整體來說很有幫助,詳細可 [**參考**](http://linux-wiki.cn/wiki/zh-tw/Linux%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84) > 此圖為 Ubuntu 路徑 > ![](https://i.imgur.com/PkspiIL.png) | 路徑 | 功能 | 其他 | | -------- | -------- | -------- | | / | **==根目錄==** | 如同 window 使用 c:\ | | /bin | ++全名為 **binary 目錄**++,這個目錄下**存放著常用的指令集** | Ex: dir/cp/ls...等等基礎指令| | /boot | Linux 啟動時使用的核心文件 | | | /dev | ++全名為 **device 目錄**++,Linux 的外部設,**其他硬碟也存在這**| 在 Linux 中訪問設備的方式如同訪問文件的方式 | | /etc | 該目錄中包含 **系統和應用軟體的配置文件** | **像是 ++環境變量++ 就會配置在這** | | /home | 用戶主目錄 | 一般該目錄是以用戶的帳號命名 | | /lib | 存放系統基本 **動態連結共享庫**,幾乎所有的應用都會使用到 | 作用如同 window 中的 dell 文件 | | /lost+found | 一般為空,當系統**非法關機就會在這裡產生紀錄文件** | 訪問該目錄需要權限 | | /media | Linux 會自動識別一些設備,識別後會掛載到 media 目錄下 | **像是 usb 等等...** | | /mnt | 系統提供該目錄是為了讓用戶++臨時++掛載 | mount 常會使用到 | | /opt | 默認為空目錄,給主機而外安裝軟體所擺放的目錄 | | | ==**/proc**== | **==虛擬目錄,用於系統內存的映射==,可通過直接訪問該目錄獲取系統訊息**,**該目錄的內容不存在於硬碟中,==存在內存中(Memory)==**| 可直接修改內部文件 | | /root | 該目錄為系統管理員,也是用戶的主目錄 | | | /sbin | ++全名為 **super Binary 目錄**++,存放系統管理員使用的系統管理程式| | | /selinux | **RedHat/CentOS 等付費系統專有目錄,功能類似於防火牆** | | | /srv | 系統啟動時需要的數據 | | | /temp | 存放臨時文件 | | | /sys | 與 /proc 類似,但主要針對硬體相關參數 | **在 linux2.6 內核中出現 sysfs,它集成了 3 種系統文件訊息**,1.++針對進程訊息的 proc 文件系統++,2.++針對設備的 devfs 文件系統++,3.++針對偽終端 devpts 文件系統++,這些文件是系統內部直接的映射,當內核對象被創建時對應的件系統也會被創建 | | **==/usr==** | 用戶的安裝應用存放的地方 | 相當於 **window 中的 Program File 檔案** | | /var | 放置 log 文件,或是其他**經常需要修改的文件** | apt-get clean 實際清理 /var/cache/apt/archives .deb 暫存文件 | | /run | 系統運行時需要的文件 | | ### usr 路徑 * **注意※usr 並不是 user,而是 Unix System Resoure**,如上面介紹他是 **==用戶所對應的實體程序 and 應用程序==** | 目錄 | 功能 | 範例 | | - | - | - | | /usr/bin | 系統該用戶使用的指令檔案 | | | /usr/sbin | 管理員(root)所使用的應用程序 | | | /usr/local/bin | 當前用戶自己的執行程序 | **在下載 Android 源碼中要使用到 python,python 就會放置在這** | | /usr/src | 內核 code 所放置的目錄 | | | /usr/lib | 存放 jvm 的位子 | 要安裝 sudo apt-get install openjdk-8-jdk | :::danger 1. Android source 下載的時候使用 repo 發現沒辦法使用 python > ![](https://i.imgur.com/ZELhMiM.png) 2. 因為目前使用 Ubuntu 18.0.4 (LTS)版本,內部就有內建 python3 (可用 whereis python3 查尋),它放置在 /usr/bin 目錄下,屬於系統指令 > ![](https://i.imgur.com/BhgQXCq.png) 3. 使用 repo 不成功的原因在 repo 它不能調用系統指令,**repo 只能調用用戶指令**,所以**使用強連結連接到 /usr/local/bin 目錄下**,就可以成功調用 ```shell= sudo ln -s /usr/bin/python3 /usr/local/bin/python ``` ::: ## 環境變量 * Linux 環境下有 2 種方式操作環境變量 profile & bashrc,在設定時**使用關鍵字 export**,**如果沒有針對文件寫入就是針對目前的終端機** ```shell= // 在目前的終端機使用,跳到令一個終端就無法使用了 export CLASS_PATH=./JAVA_HOME/lib // 對當前終端機設定環境變量 PATH=~/bin:$PATH ``` ### profile 文件 * 一般不建議在 /etc/profile 文件中新增環境變量,**在該文件下新增變數是每個使用者都會用到的**,設定後必須,**++強制生效++ 或是 ++重新登入++ 才能有效** * 在添加變量時可以使用 `;`,也可以不使用,如果有多個就必須使用 `:` 區分開\ | 檔案 | 位置 | 功能 | 特色 | | -------- | -------- | -------- | - | | profile | /ect/profile | **在這設定的變量對所有用戶生效** | **當用戶 login (登錄時),該文件會被執行,並從 profile.d 目錄的配置文件尋找 shell 設定** | | /ect/profile.d | /ect/profile.d | 這是個目錄,存放啟動登入時的 shell 文件 | | ```shell= // vim 編譯文件 vim /etc/profile // 串接 PATH 變數 export PATH=/home/aliens/<文件>:$PATH // 強制生效 sourcr /etc/profile // 測試環境,PATH 只是個變數,要呼叫必須使用 $ echo $PATH // 或是 env env ``` **--profile.d 文件--** > 啟動 profile 後會找查 shell 設定 > ![](https://i.imgur.com/vozDJLi.png) ### bashrc 文件 * bashrc 文件只會對指定的 shell 類型有作用,並且只會被 bash shell 調用 | 檔案 | 位置 | 功能 | 特色 | | -------- | -------- | -------- | - | | bash.bashrc | /etc/bash.bashrc | 設定環境變量 | **對所有用戶有效** | | .bashrc | ~/.bashrc | 設定環境變量 | **針對當前用戶設定** | | .bash_profile | ~/.bash_profile | 設定環境變量 | **針對當前用戶設定** | ```shell= // 以下修改 .bashrc 當前用戶環境變量 vim ~/.bashrc // 進入 vim 編譯,在最底下加入 export PATH export PATH=${PATH}:/home/aliens/Flutter_sdk/flutter/bin // 打印路徑 echo $PATH ``` **--實做結果--** > ![](https://i.imgur.com/lcU6EHR.png) ### 載入順序 使用者載入過程 1. /etc/profile -> /etc/profile.d/*.sh (所有 shell 檔案) 2. ~/.bash_profile -> ~/.bashrc -> /etc/bashrc 3. 載入完成 > ![](https://i.imgur.com/2HCfFUq.png) ## 文件相關 * 有分為查看**屬性、權限**等等 ### 文件屬性 | 指令 | 說明 | 範例 | | -------- | -------- | -------- | | wc | **文件行數,字數**,大部分用來查看文字文件的屬性 | wc cc.txt | | od | **文件以 ++8進位++ 格式輸出在螢幕中**,++-c ASCII++,++-d 10進位++,++-f float++,++-o 8進位++,++-s 10進位++,++-u 有號 16進位++, | od cc.txt (預設 4 byte為一組輸出 8進制) | | du | **disk use,估計檔案佔用的大小** | du cc.txt / du -hs <資料夾> | | df | **disk free**,硬碟使用狀況 | df | > ![](https://i.imgur.com/aM2My37.png) ### 文件權限-ch * 以下來看最常使用到的 **chmod 改變屬性**,全名 change mode,查看文件權限可用 ls -l * chmod 有兩種方式可以操作,**文字設定、數字設定,兩者最大的差別在於==文字設定可以針對不同群組做設定== (中間不可有空白)** | 修改方式 | 操作符號 | 範例 | | -------- | -------- | -------- | | 文字設定 | **u/g/o/a (user/group/other/all)**,+/-/= (添加/刪除/指定),r/w/x(讀/寫/執行)| chmod +rwx cc.txt \ chmod u-xw cc.txt | | 數字設定 | **+/-/= (添加/刪除/指定),4/2/1/0 由前到後代表了 rwx,最後一個是無權限** | chmod 777 cc.txt,**針對每一個群組做出設定** | * **修改所有者 chown**,sudo chown <user> <文件>,**若非持有用戶要改變必須提權** > ![](https://i.imgur.com/LL2WKHz.png) * **修改所有者 chgrp**,sudo chgrp <group> <文件>,**若非持有群組要改變必須提權** ## 搜索 ### 指令 find * 可**使用正規表達式的方式搜索,必且搜索++包括副檔名在內++** :::info 基礎正規表達式:`*` **多個**任意字元、`?`**單個**任意字元 ::: | 找尋方式 | 操作 | 範例 | | -------- | -------- | -------- | | 名稱 | find <路徑> -name <名稱> | find . *.txt / find .. *.txt / find . aa.txt | | 大小 | find <路徑> <-size> < **==+/-==** 大小>,+ 代表大於,- 代表小於,恰好等於則不須符號 | find ~ -size +10k / find ~ -size -100k| | 類型 | find <路徑> -type <類型> | f(普通文件)、d(目錄)、l(連結)、b(塊設備)、c(字符設備)、s(socket 文件)、p(管道) | 1. 依照名稱 > ![](https://i.imgur.com/cIUIBNv.png) 2. 依照大小 > ![](https://i.imgur.com/KZ0wJlE.png) 3. 依照類型 > ![](https://i.imgur.com/SD3Rrx2.png) ### 指令 grep * grep 指令並不包含在基礎指令之內,所以**必須透過 sudo apt install grap 下載** * 使用關鍵字尋找 grap -r "關鍵字" 路徑 > ## 安裝指令 安裝指令大部分要 ==**超級用戶 ++sudo++ 的權限**== 下使用,主要有分為三種 1. apt-get 2. deb 3. 源碼安裝 ### 安裝/更新 package apt | 功能 | 指令 | 功能 | 範例 | | -------- | -------- | -------- | -------- | | 安裝 | apt-get **install** <package>| 手動安裝 package | sudo **apt-get** install tree | | 安裝 | apt **install** <package> | 安裝界面,功能同 apt-get | sudo **apt** install grep | | 更新包 | apt-get **update** | 更新 package list | sudo apt-get update | | 更新套件 | apt-get **upgrade** | 更新系統套件 | sudo apt-get upgrade | | 清理 | apt-get **clean** | 清理**所有**安裝包 | sudo apt-get clean | :::info apt-get clean 實際上清理的是 apt-get clean 實際清理 /var/cache/apt/archives **.deb 暫存文**件 > ![](https://i.imgur.com/My3kucT.png) ::: ### aptitude * **才能 aptitude**,它並不屬於內部功能,要使用前必須先使用 apt-get 安裝 aptitude,它的功能比 apt-get 更完善一些,**可針對 package 進行更多操作** | 功能 | 指令 | 功能 | 範例 | | -------- | -------- | -------- | -------- | | 安裝 | aptitude **install** <package> | 手動安裝指定 package | sudo aptitude install tree | | 重新安裝 | aptitude **reinstall** <package> | 重新安裝包 | sudo aptitude reinstall tree | | 更新 | aptitude **update** | 更新包 | | | 移除 | aptitude **remove** <package> | 移除包 | | | 顯示狀態 | aptitude **show** <package> | 可顯示 package Name、版本、狀態、大小...等等 | sudo aptitude show tree | > aptitude show 的訊細 > ![](https://i.imgur.com/u1tkHet.png) * 其他詳細使用 aptitude --help > ![](https://i.imgur.com/fLw3xot.png) ### deb 包安裝 * [**Debian**](https://zh.wikipedia.org/wiki/Debian) 完全**由自由軟體組成的類UNIX作業系統**,其包含的多數軟體使用GNU通用公共許可協定授權,並由Debian計劃的參與者組成團隊對其進行打包、開發與維護 * **操作指令使用 dpkg,可記憶成 debian package** | 功能 | 指令 | 功能 | 範例 | | -------- | -------- | -------- | -------- | | 安裝 | sudo dpkg -i <package> | 安裝指定 package,-i 為 install | sudo dpkg -i xxx.deb | | 刪除 | sudo dpkg -r <package> | 安裝指定 package,-r 為 remove | sudo dpkg -r xxx | ### 源碼安裝 * 主要使用 make 指令安裝,安裝 GUN utility 維護的程式,該指令要下載 * 主要分為幾個重點步驟,**主要還要要看 ++readme.txt 的步驟++** :::info 1. 解壓縮源碼包 2. cd 進入安裝目錄 3. 檢查文件是否缺失,創建 Makefile,檢測編譯環境 : ./configure 4. 編譯源碼,生成 Lib or 可執行文程式 : make 5. 把 Lib or 可執行文程式安裝到系統目錄下 : sudo make install 6. 刪除 : sudo male distclean ::: ## 掛載 mount 有分為系統掛載、手動掛載 ::: spoiler mount 的使用 ```cmake= Usage: mount [-lhV] mount -a [options] mount [options] [--source] <source> | [--target] <directory> mount [options] <source> <directory> mount <operation> <mountpoint> [<target>] Mount a filesystem. 選項: -a, --all mount all filesystems mentioned in fstab -c, --no-canonicalize don't canonicalize paths -f, --fake dry run; skip the mount(2) syscall -F, --fork fork off for each device (use with -a) -T, --fstab <path> alternative file to /etc/fstab -i, --internal-only don't call the mount.<type> helpers -l, --show-labels show also filesystem labels -n, --no-mtab don't write to /etc/mtab -o, --options <list> comma-separated list of mount options -O, --test-opts <list> limit the set of filesystems (use with -a) -r, --read-only mount the filesystem read-only (same as -o ro) -t, --types <list> limit the set of filesystem types --source <src> explicitly specifies source (path, label, uuid) --target <target> explicitly specifies mountpoint -v, --verbose say what is being done -w, --rw, --read-write mount the filesystem read-write (default) -h, --help display this help -V, --version display version Source: -L, --label <label> synonym for LABEL=<label> -U, --uuid <uuid> synonym for UUID=<uuid> LABEL=<label> specifies device by filesystem label UUID=<uuid> specifies device by filesystem UUID PARTLABEL=<label> specifies device by partition label PARTUUID=<uuid> specifies device by partition UUID <device> specifies device by path <directory> mountpoint for bind mounts (see --bind/rbind) <file> regular file for loopdev setup Operations: -B, --bind mount a subtree somewhere else (same as -o bind) -M, --move move a subtree to some other place -R, --rbind mount a subtree and all submounts somewhere else --make-shared mark a subtree as shared --make-slave mark a subtree as slave --make-private mark a subtree as private --make-unbindable mark a subtree as unbindable --make-rshared recursively mark a whole subtree as shared --make-rslave recursively mark a whole subtree as slave --make-rprivate recursively mark a whole subtree as private --make-runbindable recursively mark a whole subtree as unbindable For more details see mount(8). ``` ::: ### 系統掛載 /media & 手動掛載 /mnt * 基本上掛載的方式都一樣,只是存放於不同資料夾內,掛載時使用的 option 操作也相同,**對固定的 option 做一些說明** :::info 1. -o loop 正常掛載 2. -t iso9660 才能使用 iso 檔案 ::: --- * **系統主要掛載存在於根目錄的 ++/media 資料夾++** * 指令格式 mount <option> <掛載檔案> <掛載目錄> > 掛載目錄 /**media**/<mkdir dir name> ```cmake= // 加載 media iso sudo mount -t iso9660 -o loop xxx.iso /media/iso // 卸載 media iso sudo unmount /media/iso ``` --- * **手動掛載通常存放於 ++/mnt 資料夾++**,可以用來掛載 iso 檔案、cdrom 檔案 * 指令格式 mount <option> <掛載檔案> <掛載目錄> > 掛載目錄 /**mnt**/<mkdir dir name> > > 掛載到 /mnt 以外的目錄:掛載成功後會遮蔽調目錄中原來的檔案,卸載後才可以看到目錄中原來的數據 ```cmake= // 加載 mnt iso sudo mount -t iso9660 -o loop xxx.iso /mnt/iso // 卸載 mnt iso sudo unmount /mnt/iso ``` ### fuseiso 掛載 * 使用 Ubuntu 的 fuseiso 可以直接掛載檔案,而不用作多的 option 設定,但是這必須要透過 apt-get 下載 * **++不需要 sudo 提權++就可以掛載** * 指令格式 fuseiso <iso 檔案> <掛載目錄> ```cmake= sudo apt-get install fuseiso fuseiso arthurtoday0103.iso /home/arthuryu/iso ``` ## 壓縮管理 ### 打包-tar * **預設僅打包 tar ++無壓縮++,所以打包後檔案大小同打包前** * **可以透過++設置參數(option)來壓縮 & 解壓縮++**,以下會介紹幾個常用的,至於全部 option 可以透過 `man` or `tar -?` 查尋 | Option | 功能 | | -------- | -------- | | z | 用 gzip 來壓縮 / 解壓文件 | | j | 用 bzip2 來壓縮 / 解壓文件 | | c | **create 創建新的壓縮文件**,如果要備份一個檔案 or 目錄就可以使用 | | x | 從封存中解開檔案 | | v | 詳細列出處理過程 (輸出資訊) | | f | **==封存==,指定壓縮文件名稱** | 1. 壓縮選項 > ![](https://i.imgur.com/Ja1c01d.png) 2. 主要操作模式 > ![](https://i.imgur.com/sfpZhKS.png) ```cmake= // 純 tar 文件 tar + <參數(cvf)> + <名稱.tar> + <目錄 or 文件> // 壓縮範例 1 gz tar + <參數(zcvf)> + <壓縮名稱.tar.gz> + <目錄 or 文件> // 壓縮範例 2 bz2 tar + <參數(jcvf)> + <壓縮名稱.tar.bz2> + <目錄 or 文件> ``` **--壓縮 實際操作--** > ![](https://i.imgur.com/QpZoQgn.png) ```cmake= // 純 tar 文件 tar + <參數(xvf)> + <名稱.tar> // 解壓縮範例 2 bz2 tar + <參數(jxvf)> + <壓縮包.tar.bz2> // 指定解壓縮目錄 添加參數 C tar zxvf test.tar.gz -C <目標目錄> ``` **--解壓縮 實際操作--** > ![](https://i.imgur.com/L8u9WSo.png) ### 壓縮 * 壓縮有分多種格式,每個格式的特性也不相同,**壓縮過後的檔案是呈現==紅色==** | 格式 | 壓縮命令 | 解壓命令 | 其他 | | -------- | -------- | -------- | -------- | | .gz | gzip <文件> | gunzip / gzip -d <文件> | **壓縮過程++不保留文件++,++不對目錄進行壓縮++,++不能對多個文件進程打包++** | | .bz2 | bzip2 <文件> | bunzip2 / bzip2 -d <文件> | **可透過 -k (keep) 保存原文件,++不對目錄進行壓縮++,++不能對多個文件進程打包++** | | .zip | zip -r <壓縮包名稱.zip> <路徑> | unzip <目標包.zip> / unzip <目標包.zip> -d <指定目錄> | **專門用來打包目錄**,解壓時可以使用 -d 指定目錄 | | .7z | 7z a <壓縮包名稱.7z> <文件> -p | 7z x <目標包.7z> | **需要安裝套件 p7zip-full,可打包目錄 or 單個文件**,**==-p 可添加密碼==** | | .rar | rar a -r <壓縮包名稱.rar ==(可不用後綴.rar)== > <目錄> -p | rar x <目標包.rar> <目錄>| **需要安裝套件 rar,可打包目錄 or 單個文件**,**==-p 可添加密碼==** | 1. gz(不能保留) / bz2(-k 可保留) **只能壓縮檔案,不能壓縮資料夾** > ![](https://i.imgur.com/rFFRUHB.png) 2. zip 壓縮資料夾 (好像不能打包單文件) > ![](https://i.imgur.com/BiCQjUP.png) 3. 7z / rar 壓縮,都可加密 > ![](https://i.imgur.com/oejMIaM.png) ## 進程管理 | 命令 | 功能 | 補充 | | -------- | -------- |-------- | | who | 查看當前在線用戶的狀況 | <登錄用戶名> <使用設備終端 (pts)> <登入系統的時間> | | whoami | 查看目前登錄用戶名 | | | **ps** | 查看整個系統內部所運行的進程 | -a 當前系統所有用戶的進程,-u 查看進程所有者以及 cpu & mem 的使用率,-x 顯示不能與用戶互交的進程,可一起使用 ps aux | | kill | 殺死進程 | kill -l <PID (ps查看)> | | env | 當前的環境變量 | **類似於 window 的 PATH** | | top | 當前運行的所有進程,並即時顯示電腦使用的狀況 (自動更新) | **類似於 window 的工作管理員** | :::info 系統化觀看可以安裝 htop ```shell= // 安裝 sudo apt-get install htop // 呼叫 htop ``` > ![](https://i.imgur.com/3uifbhC.png) ::: ## 網路管理 * ifconfig 需要下載包 **sudo apt-get install net-tools** | 命令 | 功能 | 補充 | | -------- | -------- | -------- | | ifconfig | 獲取網路接口的配置訊息,並且可修改這些配置| | | **nslookup** | 查看 DNS 相對應的 ip 地址 | nslookup www.google.com | | ping | 測試網路連線,-c 固定次數,-i 發送頻率(預設 1s) | ping 127.0.0.53 (google ip) | ## 其他指令 | 功能 | 指令使用 | 補充 | | -------- | -------- | -------- | | 終端機翻頁 | Shift + (PageUp \ PageDown) | | | 終端機**創建** | 創建新頁面 `Ctrl + Alt + T`、創建標籤頁面`Ctrl + Shift + T` | 要先換頁面使用 Ctrl + (PageUp \ PageDown) | | 清屏 | clear、`Ctrl + l` | | | 在終端機顯示數據 | echo <數據> | echo 123、echo $PATH | ## 開關指令 | 命令 | 功能 | 補充 | | -------- | -------- | -------- | | poweroff / halt | 直接關機,不是否有程序在運作 | 不推薦這個方法不安全 :-1: | | reboot | 重新開機 | 功能同 shutdown -r now | | last | 查詢關機、重起紀錄 | last -x reboot、last-x shutdown | ### shutdown * shutdown 有多種操作方式 | 操作 | 功能 | | -------- | -------- | | -k | 發送警告訊息,模擬關機,**沒有真正 shutdown** | | -c | 取消以設定的關機動作 | | -h <+time\> | 關閉程序後關機,想要立即關機 +time 可以轉為 <now\>、<+0\>、<0\> | | -h <hh:mm\> | 在規定時間準時關機,shutdown 19:30 | | -f(關閉)/-F(啟動) | 在重新開機後是否啟動 fsck 檢查 | | -t<時間> | 延遲關機時間,shutdown -t3 -r (3分鐘後重新開機) | | -r <+time\> | 重新開機,可配合時間使用 | | -n | 不經過 init 就關機,不推間 :-1: | > ![](https://i.imgur.com/T3DwJih.png) ## Appendix & FAQ :::info ::: ###### tags: `Linux 基礎`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully