HPC NTCU
      • 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
    <style> .blue { color: blue; } </style> ## Introduction Tmux 是一個用於管理多個終端會話的命令行工具,它可以在單個終端窗口或控制台中進行多個終端會話的管理。它的好處包括: - 多視窗、多窗格:可以在畫面上顯示更多內容。一邊監看工作一邊繼續其他作業。又或者是將工作留在某個視窗執行,而不需要使用shell的功能在背景和前景來回切換。 - 會話管理: Tmux 允許您創建和管理會話。會話是窗口和窗格的集合,可以保存並恢復。如果您需要從遠程服務器或計算機斷開連接,然後稍後恢復工作,這尤其有用。**尤其是避免意外的網路中斷導致工作被意外終止。** - 遠程訪問: Tmux 會話可以輕鬆分離和重新附加。這使得您可以在一台機器上啟動會話,然後分離它,然後從另一台機器重新附加到它,從而可以無縫地繼續工作。 - 會話共享: 您可以與多個用戶共享Tmux會話,允許共同在同一終端會話上合作,這對於**合作編程或提供遠程協助**非常有用。 ## 安裝 tmux 以 ubuntu 為例。 ```shell= sudo apt install tmux ``` (optional) https://github.com/gpakosz/.tmux ## 執行 tmux ```shell tmux ``` 這將創建一個 **tmux session**,並在該 session 打開一個 **window**。 :::info **tmux 基本概念** - **Session**: 一個 tmux session 是一個獨立的工作環境,可以包含多個 windows 和 panes。 - **Window**: 一個 tmux window 可以包含多個 panes。 - **Pane**: 每個 panes 可以運行不同的指令。 ::: ![](https://hackmd.io/_uploads/By1mR-EyT.png) 在狀態列中最左側的編號是目前的 session 編號,接著是目前 session 之中所有的 windows 編號以及正在執行的程式名稱,目前所處的 windows 會以星號(*)標示。 每一個 window 視窗都可以分割成多個 panes,每一個 pane 都是各自獨立的 shell,可以個別進行不同的工作。 ## tmux session command 開啟並進入新的session,其 `[session]` 是上圖中的 Session 編號 ```shell tmux new-session -s [session] ``` 列出目前所有的 sessions ```shell tmux ls ``` 進入指定session:使用`attatch`或`a`,以下兩種command等效 ```shell tmux attach -t [session] tmux attach-session -t [session] ``` 刪除指定session ``` tmux kill-session -t [session] ``` ## tmux shortcut tmux 常透過shortcut(快捷鍵)來操作,大多是 `Ctrl B` 再按其他鍵 ### Session - **`Ctrl-b d`**: disconnect,斷開 tmux session,但保持後台運行。 - <font class="blue">**`Ctrl-b s`**</font>: 以視覺化選單切換 session。 - `Ctrl-b L`: 切換至上一個使用過的 session。 - `Ctrl-b (`: 切換至上一個 session。 - `Ctrl-b )`: 切換至下一個 session。 - **`Ctrl-b $`**: 重新命名目前的 session。 ### Window - **`Ctrl-b c`**: 創建並進入新window - **`Ctrl-b ,`**: 重命名當前window - <font class="blue">**`Ctrl-b w`**</font>: 以視覺化選單切換 window - `Ctrl-b p`: 切換至上一個 window (previous) - `Ctrl-b n`: 切換至下一個 window (next) - `Ctrl-b 數字鍵`: 切換到特定編號的 window - **`Ctrl-b &`**: 關閉目前的 window ### Pane - **`Ctrl-b %`**: 開啟新的pane,與當前pane水平分割。 - **`Ctrl-b "`**: 開啟新的pane,與當前pane垂直分割。 - **`Ctrl-b 方向鍵`**: 切換 pane。 - `Ctrl-b x`: 關閉目前 pane。 - `Ctrl-b Ctrl-方向鍵`: 調整目前 pane 大小。 - `Ctrl-b 空白`: 切換布局方式。 - 把 pane 獨立為 window: 1. `ctrl+b, q` 後,出現數字 2. 選取數字 3. `ctrl+b, !` ## 在 tmux 中工作 在 tmux 視窗中執行命令,就像在普通終端中一樣。 - `Ctrl-b f`: 在所有 window 視窗中搜尋關鍵字。 - `Ctrl-b [`: 進入複製模式,可以使用箭頭鍵或 vi 風格鍵來瀏覽終端輸出。 - `q`: 退出複製模式。 ### tmux 指令模式 類似 `vim` 的指令模式,`Ctrl-b` 後按 `:` 可以進入指令模式,並可以在視窗的底部下指令進行 tmux 的操作。 - 此模式下也可以按 tab 補完指令 - 按下 tab 後會出現選單,可以用上下鍵或數字鍵選擇 ![](https://hackmd.io/_uploads/H1Dfa-Ey6.png) - 雖然操作可能比快捷鍵更慢一些,但應該比快捷鍵更好記憶 #### 建立 - Session: `new`, `new-session` - Window: `neww`, `new-window` #### 分割 pane - 水平分割: `split-pane`, `splitp`, `split-window`, `splitw` #### 刪除 - Pane: `kill-pane`, `killp` - Window: `kill-window`, `killw` - Session: `kill-session` ## 多人共用 session - 先用 `tmux ls` 確認要共用的 session 的編號 - 使用 `tmux a -t <session number>` 連接到該 session - 當多個使用者同時連線到同個 session,即可達到多人共用相同畫面的效果 ## 參考資料 - [Linux tmux 終端機管理工具使用教學](https://blog.gtwang.org/linux/linux-tmux-terminal-multiplexer-tutorial/) ## 學長補充 - 個人習慣把 tmux, vim 快捷鍵更改成類似的,只要記一套快捷鍵就好 - https://www.hostinger.com/tutorials/tmux-config

    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