NCNU-OpenSource
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners 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
    • 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 Help
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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: 1102, lsa --- # Week 02(2022/02/24) - Book mode https://hackmd.io/@ncnu-opensource/book [TOC] ## FHS - Filesystem Hierarchy Standard : 檔案系統階層標準 - 甚麼東西該擺在哪裡、哪裡該要有目錄 - 讓使用者能夠精準知道甚麼檔案會出現在甚麼路徑下 - LSB Linux Standard Base - **在 Linux 裡萬物皆是檔案** :::info - 各個顏色的意思 - 白色:一般的檔案 - 藍色:目錄 - 綠色:**可執行**的檔案 - 紅色:壓縮檔 - 黃色:設備檔 - `ls -al` 時是 c 開頭或 b 開頭(硬碟) - 淺藍色:連結檔 ::: ![](https://i.imgur.com/GgLv1Ec.png) ![](https://i.imgur.com/t6HeibR.png =60%x) ### 各目錄 - `/bin` 放基礎指令 - `/boot` 掛載 kernel 的地方,讓 OS 知道檔案放哪裡 - `/dev` device,所有硬體設備 (鍵盤滑鼠等) - 在此目錄下通常檔案權限通常是 c、d、block device - 但這個目錄中不只硬體設備,還包含虛擬硬體設備,例如:ifconfig 看到的東西也是 - `dev/shm` share memory,會直接佔記憶體的一半空間,整個系統中只有 `/tmp` 跟他的權限一樣, - 不要直接把東西丟進來,但不要隨便丟東西過來,不然會直接佔滿記憶體 - `/opt` 放第三方應用程式、軟體 - `/etc` 放設定檔的地方 - `/etc` 裡的 `opt` : 放外面根目錄的 opt 的設定檔 - `passwd` - `shadow` (這個要用 sudo) - `/home` 目前所有使用者的家目錄 - `/lib` 基本的函式庫和資料模組(?) - 32, 64 - `/media` **可移動式**媒體的掛載點 (CD 等) - `/mount` **手動**掛載的程式檔案 - `/run` 正在執行中的程式 - `__.pid` 存 process id - `/sbin` 只有 root 可以執行的指令 (reboot 等) - `/srv` service,系統提供的服務數據(啟動後所需要的資料) - `/tmp` temporary,放臨時檔案的地方 - 重新開機後會被清空 - 權限是 777 - 如果系統管理者發現電腦被駭,通常第一個會來檢查這個目錄 - `/usr` unix software resource 儲存唯讀的檔案(不影響電腦運行的程式) - 唯讀:read only - `/usr/bin` 放置可執行程式,例如執行 C/C++ 的 gcc 檔 - `/usr/sbin` 網路管理的指令 - `/usr/share` 獨立於架構的東西,例如 `man` 內建使用手冊 - `/var` 程式在一直執行的過程中會不斷地變換 - `/var/cache` 儲存快取 - `/var/lib` 狀態資訊 - 對於程式,在執行、讀取資料庫時資料庫是永久的 - `/var/lock` 用來追蹤目前使用的資源 - `/var/log` 各種記錄檔,例如放 error log - `/var/opt` 和 root filesystem 的是一樣的東西 - `/var/run` 和 `/var/opt` 一樣 - `/var/spool` 放置等待處理的離線檔案 - `/var/tmp` 系統重新啟動期間存放的臨時檔案 - `/var/www` 網站中變動的東西就存在 - ex. 網路留言板 ### FHS 沒講到但很重要的目錄(一) `/proc` `/sys` - `ls /proc/`process,把在記憶體中的一部分資訊掛載成一個目錄,這個目錄不在任何硬體上,直接對應到一個記憶體 - 在 proc 中隨意用 `sudo vim` 修改東西有可能影響 memory 中的東西,所以最好是用 `cat` 就好 - `/proc/sys` 當有使用者在系統中高度吃系統資源,去限制他 - `ps a` - `ps aux` 可以看到哪個 user 在使用哪個 process - `u` user - `x` - `ps aux | less` 顯示少一點資訊 - `less` 顯示少部分資訊資料 - `cat stat` 在 proc 中「指定的 process」的狀態 - `cat /etc/security/limits.conf` 設定各種 limits - type - soft limit - hard limit:不能再更改 - nproc : number of process - `ls fd` file description,可以看到系統中設定的 file 的詳細資訊,可以看到開了幾個 file - 調整正在運作中的系統的參數 - 如果希望短時間更改系統參數,開機後自動復原參數,可以直接改 `/proc/sys/` - 例如這個參數是 0,直接改掉它 ![](https://i.imgur.com/J5HTs5E.png =80%x) - `apt-cache search procfs` - `df` 看現在系統內有哪些分割區,用來看磁碟分配 - ![](https://i.imgur.com/BywPz4n.png =400x) - `df -h` human readable,顯示為人看得懂的,裡面就有很多虛擬/實際存在(真的會存進硬碟裡)的 - ![](https://i.imgur.com/MqZqekh.png =400x) - `dd` - `du` - `mount` 把一個硬碟磁區掛上(掛載) - `proc on /proc type proc` 特別把 proc 這種檔案系統掛載到`/proc` (?) - `umount` 與 mount 相反 - `/dev/shm` : 全部的人都可讀可寫 - 佔記憶體的二分之一 - 和 `tmp` 一樣都可讀可寫 - `tmp` 裡面有超多雜七雜八的資料(大雜燴) :::warning > 網路中說 把 swap 關掉的網站都可以 puie 他口水 [name=BT] > swap 是電腦系統的最後一層底線,它可能讓電腦跑得很慢,但不會 crash ::: :::success **補充** - postfix:mail 伺服器 #### 複製貼上 - 在 linux 中雙擊反白是複製;按下滑鼠中鍵就是貼上 - 左鍵右鍵一起按(模擬中鍵):貼上 - ctrl + shift + c 複製 - ctrl + shift + v 貼上 - ctrl 和 雙擊是不同的複製區域,會分別貼上各自存到的內容,也就是說兩個暫存區 #### 隱藏足跡的做法 - 修改 ps - 修改 log - 作為系統管理員的最佳做法: - 將 /proc 與 ps aux 數量對照,已得知是否有被修改過 - apt search unhide(套件) - 幫忙找出隱藏的 process 1. 中毒 2. 臨時的正常 process(因為有時間差造成的錯誤訊息) ::: ### FHS 沒講到但很重要的目錄(二) `/sys` ## 指令 - `cd /` 回到根目錄 - `cd ../` 回到上一個目錄 - `mkdir` 建立一個目錄 - `touch` 建立一個檔案 - `echo "{內容}" > {檔案}` 直接把內容寫入檔案 - `cat {檔名}` 顯示檔案內容 - `cp {被複製檔案的路徑&檔名} {被複製檔案的路徑or檔名}` 複製檔案 - `ls | grep {要找的檔名}` 查詢 - `|`: pipe, 連結前後的程式 - `adduser {使用者名稱}` 新增使用者 - `sudo usermod --gid {使用者1} {要加入的使用者}` 將使用者加到`{使用者1}`的群組 - `sudo su` 切換使用者 - 如何讓同一群組的人不能改動檔案? - ![](https://i.imgur.com/CPregwC.png) - `chmod {權限} {檔名}`:用數字修改權限 - `r` 讀 4 - `w` 寫 2 - `x` 執行 1 - `chmod g-w {檔名}`:用文字修改權限(+:新增, -:移除, =:設定) - `ln -s {原檔案的路徑/檔名} {目的地路徑or檔名}` 建立 soft link,只要原檔案仍存在,此連結即可使用;該檔案被刪除,此 softlink 也失效 - `rm {檔案}` 刪除檔案或 - `rm -r {目錄}` 刪除目錄 - `sudo` super user do,可以不要用 sudo 就不要用,否則權限設定可能會亂掉!!! - `apt` advance packing tool - `apt install {套件}` 下載 - `apt remove --purge {套件}` 刪除套件 (但相關資料庫或檔案不會被刪除) - `apt autoremove {套件}` 完全刪除下載檔案時相關的所有檔案 - `df` 檢查磁碟的使用量與剩餘空間 ### 為什麼 ls 出來不同型態的檔案會用不同顏色顯示

    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