Tmux and Screen
Tools that allow you to keep a command line process running if you lose connection to the remote system are useful if you are doing a long process like compiling or transfusing a large file. Tmux and Screen are two such tools.
Tmux
Tmux is a program which allows you to have persistent multiple "tabs" in a single terminal window.
- Useful
- when eg. a compilation or other operation will take a long time
- for interactive multitasking
- for exotic stuff such as pair programming
Typical tmux workflow
Start a new session
tmux new -s s1
Once in the session, run any commands as normal.
Tmux has a large number of shortcut commands too. To access a shortcut, start with the control key in combination with the lower case "b" (ctrl-b). Then follow that with the shortcut option.
To detach the session so you can logout, go home and log in again later:
ctrl-b :detach
To get that same session back later:
tmux a -t s1 #get the same session back
Other useful tmux commands:
- ctrl-b ( #switch to previous session
- ctrl-b ) #switch to next session
- tmux ls #list all sessions
- tmux kill-session -t s1 #kill a session
Create Panes and Synchronize with tmux
- tmux #start a tmux session
- ctrl-b " #split horizontally
- ctrl-b % #split vertically
- ctrl-b :setw synchronize-panes on #synchronized#
- ctrl-b :setw synchronize-panes off ctrl-b o #move through the panes ctrl-b x #kill the active pane
Screen
Screen is a Linux tool that provides the ability to launch and use multiple shell sessions from a single ssh session. When a process is started with ‘screen’, the process can be detached from session & then can reattach the session at a later time.
Typical Screen workflow
Start a new session
screen -S s1
Once in the session, run any commands as normal.
To detach the session so you can logout, go home and log in again later:
screen -d s1
To get that same session back later:
screen -r s1
To list all sessions:
screen -ls
To kill a detached session:
screen -X -S session_name kill
Screen has a large number of shortcut commands too. To access a shortcut, start with the control key in combination with the lower case "a" (ctrl-a). Then follow that with the shortcut option.
Other useful screen shortcuts:
- Ctrl-a + d #detach
- Ctrl-a + p ( #switch to previous window
- Ctrl-a + n ( #switch to next window
- Ctrl-a + k #kill the current window.
Create Panes:
- Ctrl-a + S" #split window horizontally
- Ctrl-a + | # split window vertically
- Ctrl-a + Tab # switch between the windows.