Terminal multiplexer (screen/tmux)

Table of Contents


A terminal multiplexer is a software tool that allows multiple terminal sessions to run within a single terminal window, or within a single instance of a terminal emulator. Terminal multiplexers provide a way to manage multiple terminal sessions more efficiently, and can be especially useful for users who work with many terminal windows at once, or who need to maintain terminal sessions after disconnecting from a remote server.

Some of the features provided by terminal multiplexers include:

  • Split-screen mode: allows us to divide the terminal window into multiple panes, each running a separate terminal session.
  • Session management: enables us to switch between terminal sessions, or detach from a session and resume it later.
  • Window management: provides a way to organize terminal windows into different workspaces, or tabs, for easy switching between them.
  • Copy-and-paste: allows us to copy and paste text between terminal sessions, or between different applications running on the same machine.

Two popular terminal multiplexers are screen and tmux. Both provide similar functionality, and both have their own unique features and customization options. The choice between screen and tmux is largely a matter of personal preference, and both are widely used in the Unix/Linux community.

TMUX

What is tmux?

How to use

  • To start a new session just type tmux on terminal:

    tmux
    

    you should see a green menu bar at the bottom of terminal. This means that the tmux session started.

  • To detach the tmux session type:

    tmux detach
    

    or, you can also use a short-cut command: press CTRL+b release the two keys and then press d.

  • To attach the tmux session type:

    tmux attach
    
  • Save log of tmux session:

    • To go in the command mode of tmux session use CTRL+b. Then type
    :pipe-pane "cat > tmux.log"
    

    To turn off the log run:

    :pipe-pane
    
  • Scroll inside the tmux session:

    • Press CTRL+B then immediately press `[.
      • Then one can use the normal navigation key to scroll around.

Reference:

  1. https://www.linode.com/docs/networking/ssh/persistent-terminal-sessions-with-tmux/
  2. https://hyperpolyglot.org/multiplexers

SCREEN

What is screen?

How to use screen?

  • To create a new screen just type screen on terminal

    $screen
    
  • This will open a new screen (say new terminal)

  • Then start working….

  • If you are working on lxplus then you have set set CMSSW environment again after going into screen.

  • If you want to save a log file, i.e., whatever you are doing after type the screen command then instead of simple screen type screen -L

  • To detach screen

    (ctrl A)+d
    
  • To reattach screen

    screen -r
    
  • To leave the screen

    $(ctrl A)+K   # to kill the screen
    
  • How to scroll

    • Step 1: Press “Ctrl-A” on the keyboard and press “Esc.”
    • Step 2: Press the “Up” and “Down” arrow keys or the “PgUp” and “PgDn” keys to scroll through previous output.
    • Step 3: Press “Esc” to exit scrollback mode.
  • Create a screen session and submit job without actually opening the session

    screen -dmS <screen name>
    screen -S <screen name> -X stuff '<CMD>\n'
    

    In last command \n is important, else it will just write command and wait for pressing Enter. Reference: https://serverfault.com/a/243170

Use screen command on lxplus

https://hsf-training.github.io/analysis-essentials/shell-extras/persistent-screen.html

Old Instructions

# log into lxplus
krenew -b -t -- screen -D -m
screen

Difference between tmux and screen?




Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • Vi-Editor
  • GitLab workflow for CMS-AN
  • Condor Jobs
  • Mac Settings
  • Git CheatSheet
  • sed command
  • EOS uses
  • XDAQ Basics
  • ROOT CheatSheet
  • find command
  • awk command