張可葭Ivy Chang
    • 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ###### tags: `1121` `lsa` `ncnu` # 基礎指令 - Book mode: https://hackmd.io/@ncnu-opensource/book [TOC] ## 與檔案,路徑相關 - `pwd`:print working directory,現在在哪個路徑 - `-p`:印出此目錄所連結的實體目錄位置 - `ls [path]`:list - `-a`:全部檔案,包含開頭為`.`的隱藏檔案 - `-A`:包含隱藏的全部檔案,但不包含`.` `..`這兩個目錄 - `-I`:列出所有屬性與權限等等資料 - `-d<DIR>`:印出指定的目錄資料 - `-r`:以反向排序列出檔案 - `-R`:列出目錄下所有的檔案,包含目錄下的資料夾內的所有檔案 - `-t`:依照檔案建立時間列出 - `-S`:依照檔案大小列出 - `-c`,`-u`:查看特定的檔案變動時間 - Modification Time(mtime) - 預設顯示 - 檔案內容最後的變更時間 - Status Time(ctime) - `-c` - 檔案狀態最後的變更時間 - e.g.權限,屬性 - Access Time(atime) - `-u` - 檔案被讀取的最後時間 - 各欄位意義 -檔案類型 - `clear`:清空terminal畫面 - 快捷鍵:ctrl+shift+L - `cd`:change directory,變換目錄 - cd[相對路徑] - cd[絕對路徑] - cd[特殊目錄] - `.`:當前目錄 - `..`:上一層目錄 - `~`:當前user的家目錄,直接下cd也可以回家目錄 - `~ <username>`:指定user的家目錄 - `mkdir<DIR_name>`:新增資料夾 - `mkdir -p <DIRpath/DIR_name>`:如果後面的路徑不存在,可以 - `touch`< filename >:更新檔案的 m/c/atime - 如果檔案不存在會建立空檔案 - `cat<filename>`:concatenate,檢視指定的檔案內容 - `-b`:印出行號,空白行不標記 - `-n`:印出行號,空白行也標記行號 - `-T `:會把TAB按鍵用^|顯示出來 - `wc`:印出行數,字元數,位元數 - `-l`:印出行數 - `-w`:印出字元數 - `-c` :印出位元數 - `rm<filename_or_DIR>`:刪除指定的內容 - `-r`:recursive,會把目錄裡的檔案跟目錄刪除 - `-f`:force :::danger 把 root 資料夾刪掉 (會弄壞電腦) ``sudo rm -rf --no-preserve-root`` ::: - `mv`:移動或更名 - `mv <source><destination>`:移動 - `mv <file_or_DIR><new_name>`:更名 - `echo`:在terminal上印出字串或變數 - `-n`:不換行 - `echo "print(\"hello world\")"> hello.py` - `*echo $PATH*` `cp <source> <dstination>:copy` - `-a`:複製檔案的全部特性 - `-p`:連同檔案的權限、owner、時間一起複製,常用於備份 - `-r`:recursive,複製整個目錄 - `-s`:建立檔案的symbolic link(softlink),等同ln -s - `-l`:建立檔案的hardlink,等同ln `|:pipeline`:用於串接指令 - `echo '1234' | base64` - `echo '1234' | md5sum` :::info ### 一些符號 - `>`,`>>` - 標準輸入 (stdin) - 代碼:0 - `<`,`<<` - 標準輸出 - 代碼:1 - `2>`: - 標準錯誤輸出(stderr) - 代碼:2 - `|`:pipelines,把前一個指令的輸出當下一個指令的輸入 - `$`:解析變數內容 - `&`:背景執行 ::: ## 與查詢相關 - `man<something_you_want_to_know>`:maunal,查詢相關操作手冊 <!-- - `less<filename>`:查看檔案內容 - 空白建:下一頁 - `b`:上一頁 - Enter:下一行 - `q`:離開 - `/string:`搜尋指定的字串 --> - `head <filename>`:擷取檔案前幾行,顯示預設前10行 - `-n`:指定顯示的行數 - `tail`:擷取檔案後幾行,顯示預設後10行 - `-n`:指定顯示的行數 - `grep "keywords"`:從輸出中找指定的關鍵字 - `-i`:不分大小寫搜尋 - `"^keywords"`:以keywords開頭搜尋 - `grep 'regular expression'` :::info - grep 後面欄位設計可以填 正規表達式 (regular expression). - 在 pipe 東西進來之前, 要確認指令是否支援標準輸出. ::: - `whereis <filename_or_DIR>`:由一些特定的目錄中,尋找檔案檔名 - `-l`:可以列出whereis會去查詢的幾個主要目錄 - `-b`:只找binary格式檔案 - `-m`:只找在說明檔manual路徑下的檔案 - `-s`:只找source來源檔案 - `-u`:搜尋不在上述3個項目當中的其他特殊檔案 - `which<欲尋找的執行黨>`:列出第一筆由PATH目錄中找到的結果 - `-a`:將所有找到的指令均列出 ### 使用者相關指令 - `sudo <command>`:super user do , 輸入使用者的密碼用root的身分執行指令 :::success - `su`:輸入root的密碼改變身份 - 不要用su登入root管理主機 - `sudo su <username>`:切換使用者 - 把環境reset成目標使用者的環境變數 ::: - `whoami`:現在是哪個使用者 - `id`:查看自己的uid,所屬群組的gid - `sudo-id<others_username>`:root查詢其他使用者UID,GID - 系統是透過uid辨識使用者 - uid放在/etc/passwd第三個欄位 - 可以下cat /etc/group | grep< username>對照是否相同 - `sudo adduser<new_username>`:創建使用者與他的家目錄 - `sudo deluser<username>`:刪除使用者 - `exit`:登出現在的使用者 - `last`:列出使用者登入的資訊 - `/var/log/wtmp` :內容編碼過,所以用`last`指令查詢 - `-n<number>`:指定顯示的列數 - `w`:現在有哪些登入的使用者 - `passwd`:修改密碼 - `groups`:顯示出目前的使用者的所屬群組 - 第一個群組為有效群組 - 新增檔案的擁有者為有效群組 - 其他為支援群組 - `sudo groupadd <群組名稱>`:新增群組 - `-g<num>`:自訂UID - `sudo groupdel <群組名稱>`:刪除群組 - 在沒有使用者把這個群組當作inital group的情況下才能刪除 - 查看 /etc/passwd 第四個欄位 - `gpasswd`:群組管理相關指令 - 系統管理員root可執行 - `sudo gpasswd <grpname>`:設定群組密碼 - `sudo gpasswd -A <username> <grpname>`:將指定user新增至群組管理員 - `sudo gpasswd -M <username> <grpname>`:新增user進群組 - `sudo gpasswd -r <grpname>`:刪除該群組的密碼 - 群組管理員可執行的指令 - `gpass -a <username> <group_name>`: 將指定user新增至群組 - `gpass -d <username> <group_name>`: 將指定user從群組刪除 - `newgrp <group_name>`:切換有效群組 ## 與權限相關 - `chown`:change owner,改變檔案或目錄的擁有者 - 要是現有的使用者才可以成功執行 `chown` - `chown <user_name> <dirname/filename>` - `chown :<group_name> <dirname/filename>` - `chown <user_name>:<group_name> <dirname/filename>` - `-R`:recursive,可以連同目錄底下的檔案一起變更使用者 - `chgrp <group name> <dirname/filename>`:change group,改變檔案 - `-r`:recursive,常用於目錄變動 - 要是現有的群組才可以成功執行`chgrp` - `chmod <???> <file_or_dir>:改變使用者權限` - `-R`: recursive - 數字類型 - ![](https://hackmd.io/_uploads/SkpLM50ba.png) - chmod 755<filename/dir_name>:owner可讀可寫可執行,其他 - Q:`-rw-r--r--`權限怎麼改? - A:`644` - 符號類型 - `chmod<人 動作 權限設定,...> <file_or_dir>` - 人:u,g,o,a(所有人) - 動作:+(加入),-(除去),=(設定) - 權限設定:r,w,x - Q:`-rw-rw-r--`怎麼改成 `-rwxr-xr-x`? - A:`u+x,g-w+x,o+x` - 權限的意義 - 權限之於檔案 - `r`:可讀取檔案內容 - `w`:可編輯檔案內容,但沒有刪除檔案的權限 - `x`:可以把檔案內容給系統執行 - 權限之於目錄 - 目錄是一張記錄檔案名稱的清單 - `r`:可讀取這張清單 - `w`:可編輯這張清單,等同可以編輯名稱,新增,刪除,移動該目錄底下的檔案或目錄 - `x`:可以`cd`進目錄 - 所以要開放目錄給大家看的話,至少要給`r-x`的權限 :::info ### 檔案特殊權限 #### SUID - Set UID - 指令設定 - `chmod 4??? <filename>` - `chmod u+s <filename>` - 只能用在二進位檔案 - 在執行程式的當下切換成 owner 的權限 - 提權或降權 ::: ```C= #include <stdio.h> #include <unistd.h> int main() { printf("The uid is: %d\n", geteuid()); return 0; } ```

    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