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
    • 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 Versions and GitHub Sync Note Insights 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    要寫共筆喔!!! by 助教 - Book mode: https://hackmd.io/@ncnu-opensource/book [TOC] --- ## Vim ![9h7ykil4t8591](https://hackmd.io/_uploads/HywqCSA1ke.jpg) * Update 系統套件資訊: `sudo apt update` * Download : `sudo apt install vim` * Vim 最主要有分成兩種模式,normal mode 和 insert mode,在進入 vim 後會是 normal mode。 - 在 normal mode 可以使用方向鍵或 `h`、`j`、`k`、`l` 移動游標。 - 在 normal mode 輸入 `i` 會進入 insert mode - 在 insert mode 按下 Esc(鍵盤左上角) 會回到 normal mode - 在 normal mode 輸入 `:` 會進入 command mode,接著輸入 `wq` (`w`:儲存、`q`:離開)後按下 Enter 會存檔離開 vim > 更多 vim 的指令參考 : [Vim Cheat Sheet](https://vim.rtorr.com/) ## 常用指令 ### `cp` filename new_filename - stand for **copy** - 複製資料夾 cp -r - 複製權限 cp -p ```bash= # 複製 test.txt 這個檔案並將其命名為 new.txt cp test.txt new.txt # 檢查 ls ``` - `cp -a` : archieve。 > 複製完的檔案會和原本檔案的權限一樣 ### `mv` - stand for **move** - 移動檔案/重新命名 ```bash= # 改變路徑 : 將 test.txt 移動到 /folder 底下 mv test.txt /folder # 重新命名 : 將 test.txt 重新命名為 new.txt mv test.txt new.txt # 檢查 ls ``` ### `rm` - stand for **remove** - `-r` recursive - `-f` force `su` username - 切換使用者 - 不要用su切換root帳號 - `exit` 退出 ### `adduser` - 會自動建立使用者 home 目錄 - `sudo adduser username` - 會多建一個group `useradd` :::info 1. `cat /etc/passwd` * user 的帳號密碼檔,每一筆都是一位 user 的資料。 * etc 的檔案為設定檔 * 欄位 : 使用者名稱`:` 密碼 `:` user ID `:` group ID `:` 使用者描述 `:` home 目錄 `:` 登入 shell 2. `cat /etc/sudoers` * 設定 user 的權限,例如:如果 user 需要 sudo 權限。 3. `cat /etc/group` * 欄位 : 使用者名稱`:` 密碼 `:` group ID ` ::: :::info #### 為何沒有特殊理由不要用 su,而是用 sudo 除非你非常清楚你在幹麻,或想切換使用者,理由: 1. 不必共享 root 密碼 2. 可用 sudoers 控管誰有超級使用者權限,因為下 sudo 是用自己帳號密碼 3. 做錯事情可追溯,是誰用了 sudo 做一件事都會紀錄在案 ::: ### 環境變數 * `export` * `env` : * = environment * 印出所有環境變數 : 大部分和使用者相關的參數, * PWD : 目前所在目錄 * SHELL * LANG(=language) * OLDPWD(剛剛所在目錄) * PATH * 重要,可以做惡意攻擊 * 決定下的指令時找到否,該去哪些檔案找 -> 根據順序找,檔案根據`:`隔開) * `cat ~/.bashrc` : bash 啟動時會讀家目錄底下的這個檔案 * `cat ~/.profile` : * `cat /etc/skel/.` -> Tab 雙擊(印出底下所有 `.` 開頭的檔案/目錄) * 在新增使用者並建立家目錄時,就會把skel目錄中的所有檔案複製過來。 ### `diff` - 印出兩個檔案的內容不同之處 - DEMO : `diff /etc/skel/.bashrc ~/.bashrc` - 完全一樣(不會輸出任何內容) ### `man` command_name - stand for manual - `man 你想查的指令` ### `date` - 顯示日期、時間 - DEMO: - `locale` : 該 user 所有和語言相關的設定 - `env | grep LANG` : 抓 env 裡`LANG`內容 ### UID GID - 查看UID`id -u username` - 查看GID`id -g groupname` - 更改ID`sudo vim /etc/passwd` 例:把b的UID改成與a一樣,su b 就會切換到a ### `groupadd` - 建立一個新的群組 - `sudo groupadd <groupname>` ### `chmod` * 用二進位的方式設計 * 順序 : * `r` : 讀 (4) * `w` : 寫 (2) * `x` : 執行 (1) * SGID:設定之後可以讓群組內的使用者一起使用 * SUID:讓能使用檔案的人,都以 owner 的身分使用 :::info - SUID 的小 LAB - `vim printUid.c` - ```c= #include <stdio.h> #include <unistd.h> int main() { printf("The uid is: %d\n", geteuid()); return 0; } ``` - `sudo apt install gcc` - `gcc printUid.c -o printUid` - `./printUid` - `sudo chown root printUid` - `sudo chmod 4755 printUid` - `./printUid` ::: ### head * 開頭前幾筆資料,預設10筆 * `-n` : 可以指定顯示開頭 n 筆資料 ```bash= head /etc/passwd head -n 5 /etc/passwd ``` ### tail * 最後幾筆資料,預設10筆 * `-n` : 可以指定顯示最後 n 筆資料 * `-f` : 實時監控檔案的變動(常用於監控日誌) ```bash= tail /etc/passwd tail -n 5 /etc/passwd tail -f logfile.log ``` ### more ### echo - `echo $$` 顯示目前檔案的Pid ### top - 系統目前狀況 ### ps - process 資訊 ### history * 顯示執行過的指令 ### alias * 設置指令別名(可以設置經常用、太長、不容易記住的指令,下次執行時可直接下該別名) - 簡化指令(例:顯示所有檔案) ```bash= # 在 ~/.bashrc 或 ~/.bash_aliases 中加入 alias la='ls -A' ``` 重新載入 `.bashrc` ```bash= source ~/.bashrc ``` ### lsblk - 系統磁碟分配狀況 ### mktemp * 在 /tmp 目錄底下自動新建一個檔案(檔名隨機) ### 常見的文字處理組合技 combo #### 寫入 `>` vs. `>>` ```bash= # 新建 tt.txt touch tt.txt ## 將 'ls' 寫入檔案 # '>' 覆蓋原本內容 ls > tt.txt # '>>' 寫到原本內容後方(append) ls >> tt.txt ``` #### pipe : `|` ```bash= # 將前面的 standard output / stdout(file descriptor= 1) 丟到後面的 standard input / stdin (file descriptor = 0) ls | tee tt.txt ``` #### standard error `2>&1` * 寫一個有錯誤的 python 檔 hello.py * `python3 hello.py` -> 此時顯示錯誤訊息 * `python3 hello.py > HW.txt` -> 嘗試寫入 HW.txt,會發現 HW.txt沒有內容 * `python3 hello.py > HW.txt 2>&1` * `1` : 標準輸出, standard output * `2` : 標準錯誤輸出, standard error * `2>&1` : 將標準錯誤輸出重導向(redirect)到標準輸出 #### `grep` with REGEX - stand for **global regular expression print** - `ls | grep passwd` - `ls | grep p.*d` - `.` : 任意字元 - `*` : 前一個字元包含 0 到任意的數量 - 所以 `p.*d` 代表配對開頭是 `p`,結尾是 `d` 的字串 - `ls -l | grep 2022` - 找出 2022 的檔案 #### `awk` - `ls -l | grep 2022 | awk '{print $5 "\t" $9}'` - `awk` 講解: - `$<num>` : 每筆資料根據空格隔開計算第幾欄 - `print $5` 印出第 5 欄的意思 #### `sort` - `ls -l | grep 2022 | awk '{print $5 "\t" $9}' | sort -n` - `sort` : 排序,預設 ascii 第一字元大小 - `sort -n` : 數字排序 - `sort -r` : reverse #### `uniq` - 針對指令輸出唯一值 - 如果檔案長這樣, ex: wooo.txt ```= a a a b ``` - `cat wooo.txt | uniq` - `cat wooo.txt | uniq -c` - `-c` : 計算重複出現幾次 - `cat wooo.txt | sort | uniq` - `cat wooo.txt | sort | uniq -c` - `cat wooo.txt | uniq -c | sort -n` - `cat wooo.txt | uniq -c | sort -nr` - `r` : reverse反向排序 - 對系統管理者要看 log 檔很有用,例如 - `cat /var/log/syslog | awk '{print $2}' | uniq -c` ### `sl` 會考喔 * 用來嘲笑的 * `sudo apt install sl` * `sl`

    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