camioljoyce
    • 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
    • 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 Versions and GitHub Sync Note Insights 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Linux常用指令 ## ssh登入 ```linux=\ ssh 帳號@主機連線資訊 ``` ## ssh Tunnel(跳板/通道) 如果要連結的主機防火牆不通, 可以先連到同網段可以連線的主機, 在上面設Tunnel: 連線資訊為欲連結過去主機的連線資訊 設一組自訂的listening port ![](https://i.imgur.com/StacyiN.jpg) 然後再另外建立ssh連線,連線資訊設127.0.0.1 port輸入剛自訂的listening port 即可連線 ![](https://i.imgur.com/liRmfHb.jpg) --- ## 解壓縮檔案及目錄例子: ### unzip 用 unzip 將 file.zip 壓縮檔內所有檔案及目錄解壓到當前目錄: ```=\ unzip file.zip ``` 假如只想解壓壓縮檔內其中一個檔案, 可以加上檔案名稱, 例如解壓 file.zip 內的 test.pdf 檔案: ```=\ unzip file.zip test.pdf ``` 將壓縮檔所有檔案解壓到指定目錄, 可以用 -d 參數設定, 以下假設解壓到 /home/phpini ```=\ unzip file.zip -d /home/phpini ``` 列出壓縮檔所有內容: ```=\ unzip -l file.zip ``` ### tar tar 指令的常用語法 常用參數 ```= -c 打包一個 tar 檔案 -x 解開一個 tar 檔案 -t 檢視 tar 檔案的內容 -z 使用 gzip 壓縮 -v 顯示建立 tar 檔案的過程 -P 使用絕對路徑 -f 指定 tar 檔案的檔案名稱。此參數的後面要接檔案名稱,因此要注意參數的順序 (通常是把 f 參數寫在最後一個,或者是與其它參數拆開使用) ``` **常用語法:** - 建立壓縮檔 ```=\ tar -czvf 檔案名稱.tgz 來源檔案 ``` >將 來源檔案 壓縮後,打包成一個名稱為 檔案名稱.tgz 的壓縮檔,來源檔案 可以是檔案或目錄。 來源檔案 也可以有很多個,以空白字元分隔: ```=\ tar -czvf 檔案名稱.tgz 來源檔案1 來源檔案2 ... 來源檔案n ``` - 檢視壓縮檔的內容 ```=\ tar -tzvf 檔案名稱.tgz ``` - 解開壓縮檔的檔案到目前的目錄 ```=\ tar -xzvf 檔案名稱.tgz ``` - 複製目錄 ```=\ tar -cvf - 來源目錄 | tar -xvf - ``` 將 來源目錄 下的所有檔案及子目錄複製到目前的目錄,這樣做的好處是可以保留原來的檔案屬性。 --- ## nohup 指令用法 如果想讓程式可以在離線或登出之後繼續執行,可以使用 nohup 這個指令來執行程式。 nohup 的用法很簡單,只要將要執行的程式放在 他的參數中即可,而通常我們會在尾端加上 & 把這個程式放在背景執行: ```=\ nohup /path/my_program & ``` nohup 在執行程式時,會將所有的輸出訊息導入 nohup.txt 這個文字檔,所以若要觀察程式的輸出,就要從這個檔案中查看: ```=\ cat nohup.txt ``` 也可以使用 tail 自動即時顯示最新的輸出: ```=\ tail -f nohup.txt ``` **指定輸出檔案** 我們也可以透過重新導向輸出,將程式的輸出導入自己指定的檔案中: ```=\ nohup /path/my_program &> my_log.txt & ``` **這樣就會將程式的輸出導入 my_log.txt 這個檔案中。** 我們也可以將正常的訊息與錯誤訊息分開: ```=\ nohup /path/my_program > my.out 2> my.err & ``` ### Linux shell中有三種輸入輸出 #### 0 表示鍵盤輸入 1表示標準輸出 2表示錯誤輸出 #### 將程式在背景執行,並且輸出到output.txt,把錯誤輸出訊息寫到標準訊息的位置,再和標準訊息一起寫到標準輸出文件 ```=\ nohup /path/my_program > output.txt 2>&1 & ``` --- ## ls 檢視檔案與目錄 指令:ls -參數 目錄或檔案 常用參數: -a:列出所有檔案,包含隱藏檔( 開頭為 . 的檔案) -h:可將檔案容易以易讀式呈現(EX:GB、 KB、…) -l:將資料以列表形式呈現,並且包含檔案細部資料(屬性、權限、時間…) -r:反向排序(原先是從a->z變成z->a) -R:將目錄下的子目錄檔案一起列出(白話:整個資料夾檔案列出) -S:用檔案大小排序 -t:用時間排序 ```=\ ls -al 會列出所有檔案的詳細資料和權限 ``` --- ## 檔案相關指令 chgrp: 改變檔案所屬群組 chown: 改變檔案擁有者 cp: 複製檔案 chmod: 改變檔案的權限 ls: 顯示目錄下之檔案 **chown -R user:group file** ```=\ chown -R niaap:niaap mule ``` 利用 chown 可以將檔案的擁有者加以改變。一般來說,這個指令只有是由系統管理者(root)所使用,一般使用者沒有許可權可以改變別人的檔案擁有者,也沒有許可權可以將自己的檔案擁有者改設為別人。只有系統管理者(root)才有這樣的許可權。 **-R(recursive) 以遞迴方式改變目錄以及所有子目錄的使用者識別碼,若是有符號連接檔則亦會被改變。** --- ## top 用法 top是效能分析工具,能夠即時顯示系統中各個行程的資源佔用狀況 ![](https://i.imgur.com/fBgonRW.jpg) 可以看到CPU和Memory占用程度 按下空白鍵可以更新最新狀況 --- ## 時間相關指令 印出今天日期 ```=\ echo "$(date)" ``` ![](https://i.imgur.com/xcslqRr.jpg) **年月日 時分秒 毫秒** **%Y%m%d_%H%M%S%N** 設定日期變數: ```=\ today=$(date +'%Y%m%d_%H%M%S%N') echo "$(date)" ``` ![](https://i.imgur.com/eqst8I4.jpg) --- **curl用法** ```\ -X/--request [GET|POST|PUT|DELETE|PATCH] 使用指定的 http method 來發出 http request -H/--header 設定 request 裡所攜帶的 header -i/--include 在 output 顯示 response 的 header -d/--data 攜帶 HTTP POST Data -v/--verbose 輸出更多的訊息方便 debug -u/--user 攜帶使用者帳號、密碼 -b/--cookie 攜帶 cookie(可以是參數或是檔案位置) -k/--insecure 允許連接到 SSL,而且不需使用憑證 ``` EX: ```\ curl -v -X OPTIONS https://網址 ``` Console: ```\ < HTTP/1.1 200 OK < Server: Apache-Coyote/1.1 < Strict-Transport-Security: max-age=0 < X-Frame-Options: DENY < X-Content-Type-Options: nosniff < X-XSS-Protection: 1; mode=block < Allow: GET, HEAD, POST, PUT, DELETE, OPTIONS < Content-Length: 0 < Date: Fri, 26 Feb 2021 09:09:12 GMT ``` --- 在不同主機上面複製檔案 ``` scp /路徑/檔名 使用者@主機IP:/路徑/檔名 ``` --- 查看 哪些port 被程式佔用 ``` netstat -tulpn | grep LISTEN ``` 查看 8080 port被誰佔用 ``` netstat -tulpn | grep :8080 ``` ###### 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