|
|
Line 1: |
Line 1: |
| Screen allows for multi window connection using a single ssh session. It also allows to detach from the session screen while still running a remote session. | | Screen allows for multi window connection using a single ssh session. It also allows to detach from the session screen while still running a remote session. |
|
| |
| = Screen =
| |
| sudo apt-get install screen
| |
|
| |
| == Key terms ==
| |
| * '''window''' - it's a separate window that you can switch between
| |
| * '''region''' - your terminal screen can be divided in regions where each can hold multiple windows
| |
|
| |
| == Useful commands and key bindings ==
| |
| <source>
| |
| $ screen -ls #list detached sessions
| |
| $ screen -r #re attach
| |
| </source>
| |
|
| |
|
| |
| ;Quick start
| |
| *<code>C^a c</code> create new prompt
| |
| *<code>C^a tab</code> move to a next window
| |
| *<code>C^a |</code> split vertically
| |
| *<code>C^a S</code> split horizontly
| |
| *<code>C^a \</code> kill all windows, terminate any ssh sessions and exit GNU Screen program
| |
|
| |
|
| |
| ;Key bindings
| |
| {|
| |
| ! Key
| |
| ! Action
| |
| ! Notes
| |
| |-
| |
| | <code>Ctrl+a c</code>
| |
| | new window
| |
| |
| |
| |-
| |
| | <code>Ctrl+a n</code>
| |
| | next window
| |
| | I bind F12 to this
| |
| |-
| |
| | <code>Ctrl+a p</code>
| |
| | previous window
| |
| | I bind F11 to this
| |
| |-
| |
| | <code>Ctrl+a "</code>
| |
| | select window from list
| |
| | I have window list in the status line
| |
| |-
| |
| | <code>Ctrl+a</code>
| |
| | previous window viewed
| |
| |
| |
| |-
| |
| |
| |
| |
| |
| |
| |
| |-
| |
| | <code>Ctrl+a S</code>
| |
| | split terminal horizontally into regions
| |
| | <code>Ctrl+a c</code> to create new window there
| |
| |-
| |
| | <code>Ctrl+a <nowiki>|</nowiki></code>
| |
| | split terminal vertically into regions
| |
| | Requires screen >= 4.1
| |
| |-
| |
| | <code>Ctrl+a :resize</code>
| |
| | resize region
| |
| |
| |
| |-
| |
| | <code>Ctrl+a :fit</code>
| |
| | fit screen size to new terminal size
| |
| | <code>Ctrl+a F</code> is the same. Do after resizing xterm
| |
| |-
| |
| | <code>Ctrl+a :remove</code>
| |
| | remove region
| |
| | <code>Ctrl+a X</code> is the same
| |
| |-
| |
| | <code>Ctrl+a tab</code>
| |
| | Move to next region
| |
| |
| |
| |-
| |
| |
| |
| |
| |
| |
| |
| |-
| |
| | <code>Ctrl+a d</code>
| |
| | detach screen from terminal
| |
| | Start screen with -r option to reattach
| |
| |-
| |
| | <code>Ctrl+a A</code>
| |
| | set window title
| |
| |
| |
| |-
| |
| | <code>Ctrl+a x</code>
| |
| | lock session
| |
| | Enter user password to unlock
| |
| |-
| |
| | <code>Ctrl+a [</code>
| |
| | enter scrollback/copy mode
| |
| | Enter to start and end copy region. <code>Ctrl+a ]</code> to leave this mode
| |
| |-
| |
| | <code>Ctrl+a ]</code>
| |
| | paste buffer
| |
| | Supports pasting between windows
| |
| |-
| |
| | <code>Ctrl+a ></code>
| |
| | write paste buffer to file
| |
| | useful for copying between screens
| |
| |-
| |
| | <code>Ctrl+a <</code>
| |
| | read paste buffer from file
| |
| | useful for pasting between screens
| |
| |-
| |
| |
| |
| |
| |
| |
| |
| |-
| |
| | <code>Ctrl+a ?</code>
| |
| | show key bindings/command names
| |
| | Note unbound commands only in man page
| |
| |-
| |
| | <code>Ctrl+a :</code>
| |
| | goto screen command prompt
| |
| | up shows last command entered
| |
| |}
| |
|
| |
| == Scroll back - a copy mode ==
| |
| In GNU Screen press <code>Ctrl + a + [</code> or <code>C^a C^ESC</code> to enter Copy Mode, then scroll PgUp/PgDown or up/down using keys j or k. Use Enter key to start and end selection coping to registry/buffer. Below are some other navigation keys:
| |
|
| |
| h - Move the cursor left by one character
| |
| j - Move the cursor down by one line
| |
| k - Move the cursor up by one line
| |
| l - Move the cursor right by one character
| |
| 0 - Move to the beginning of the current line
| |
| $ - Move to the end of the current line.
| |
| G - Moves to the specified line
| |
| (defaults to the end of the buffer).
| |
| C-u - Scrolls a half page up.
| |
| C-b - Scrolls a full page up.
| |
| C-d - Scrolls a half page down.
| |
| C-f - Scrolls the full page down.
| |
| PgUp / PgDown - Scrolls a page up/down
| |
|
| |
| Define scrollback buffer size start screen with the following key (5000 lines in this example):
| |
| screen -h 5000
| |
|
| |
| Update: You can use activate copy mode of GNU Screen also by Ctrl + Esc that might be more useful than Ctrl + a + [ shortcut (thanks to Yu-Jie Lin for this tip).
| |
|
| |
| == Custom configuration ==
| |
| By default the config is kept in <code>~/.screenrc</code> file but using -c option we can pass a custom config
| |
|
| |
| ~$ screen -c screen-4regions.screen
| |
|
| |
| Example of a config file:
| |
| <source>
| |
| ~$ cat screen-4regions.screen
| |
| layout FourScreens #it's a new feature, makes screen aware of regions layout
| |
| # Region 0
| |
| screen -t mail1-queue #creates new terminal/prompt
| |
| select 0 #select window0
| |
| stuff "echo Window0^M" #echo a string between quotes, ^M translates to EOL means enter-return key
| |
| stuff "sshpass -p 'password' ssh -o PubkeyAuthentication=no root@example.com^M" #ssh interactively
| |
|
| |
| split #split horizontally
| |
| split -v #split vertically
| |
|
| |
| # Region 1
| |
| select 1
| |
| focus #get focus on a selected region
| |
| screen -t mail2-queue sshpass -p 'password' ssh -o PubkeyAuthentication=no root@example.com
| |
| #create a new terminal/prompt '''-t mail2-queue''' in the focus window and
| |
| #executes the command
| |
| stuff "echo Window1^M"
| |
|
| |
| # Region 2
| |
| select 2
| |
| focus
| |
| screen -t mail1
| |
| stuff "echo Window2^M"
| |
|
| |
| split -v
| |
|
| |
| # Region 3
| |
| select 3
| |
| focus
| |
| screen -t mail2
| |
| stuff "echo Window3^M"
| |
|
| |
| altscreen on
| |
| term screen-256color
| |
| bind ',' prev
| |
| bind '.' next
| |
| #
| |
| #change the hardstatus settings to give an window list at the bottom of the
| |
| #screen, with the time and date and with the current window highlighted
| |
| hardstatus alwayslastline
| |
| #hardstatus string '%{= kG}%-Lw%{= kW}%50> %n%f* %t%{= kG}%+Lw%< %{= kG}%-=%c:%s%{-}'
| |
| hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'
| |
| #layout save default #makes regions saved when you re-attach a session
| |
| </source>
| |
|
| |
|
| = Tmux = | | = Tmux = |
Screen allows for multi window connection using a single ssh session. It also allows to detach from the session screen while still running a remote session.
Tmux
Sessions, windows, panes
Tmux is a so-called terminal multiplexer. Simply speaking, tmux acts as a window manager within your terminal1 and allows you to create multiple windows and panes within a single terminal window. Within one terminal window you can open multiple windows and split-views (called “panes” in tmux lingo). Each pane will contain its own, independently running terminal instance. This allows you to have multiple terminal commands and applications running visually next to each other without the need to open multiple terminal emulator windows.
The server holds sessions and the windows and panes within them:
- session - is a set of windows, plus a notion of which window is current,there may be multiple sessions on a server,
- window(tab) - is a single screen covered with panes, each session may have many separate windows that you can switch between
- pane - is a rectangular part of a window that runs a specific command, e.g. a shell

Install Tmux
- Install - linux - use package manager
sudo apt-get install tmux
- Install - Windows
- Quick Start
/usr/bin/tmux
Managging sessions
tmux new -s database #start new session named 'database'
tmux ls #lists all detached sessions
tmux attach -t 0 #attach to terminal 0 session
tmux rename-session -t 0 database
tmux switch -t <session_name>
tmux kill-session -t <session_name>
- Key bindings
C^b :new<CR>
new session
C^b $
name session
C^b (
previous session
C^b )
next session
C^b L
'last' (previously used) session
C^b s
choose a session from a list
Key bindings
C^b c
create a window aka new virtual desktop, it creates a full size window on top of your panes
C^b "
split a pane horizontly
C^b %
split a pane vertically
C^b z
full screen pane resize, repeat to get back
C^d
close a pane, also type 'exit'
C^b Up,Down,Left,Right arrow
move to neighbouring pane
C^b q #index
display pane numbers, then press 0..9 to move to #paneIndex
C^b 0-9
move to the window based on index
C^b [] {}
swap panes [] left-right, {} up-down swap
C^b ,
rename the current window
C^b d
detach the current session
C^b D
gives you a choice what session you wish to detach
- Screen navigation, scroll and search
Function vi emacs
-------- -- -----
Half page down C-d M-Down
Half page up C-u M-Up
Next page C-f Page down
Previous page C-b Page up
Scroll down C-Down or C-e C-Down
Scroll up C-Up or C-y C-Up
Search again n n
Search again in reverse N N
Search backward ? C-r
Search forward / C-s
Copy-paste default mode (Emacs style)
Ctrl+b,[ # enter 'copy mode'
# navigate using arrows to text you want to start coping
Ctrl+Space # start coping (highlighting)
# move around using arrow keys to select region
Ctrl+w or Alt+w # copy the region into the buffer
Ctrl+b,] # paste in a possibly different Tmux pane/window
C^b,:show-buffer # show current buffer
Restore tmux environment after system restart.
Create and manage tmux sessions easily.
Terminator
Terminator is user frendly, gui scalable terminal with layouts, multi windows, tabs and broadcast function
$ sudo apt install terminator
Useful key bindings
Alt+Arrow Move to another terminal
C^+Shift+X Maximise current window, press again to revert
C^+Shift+Z Zooms the current terminal, press again to revert
C^+Shift+O Split terminals Horizontally.
C^+Shift+E Split terminals Vertically.
C^+Shift+Arrow Resize windows by moving parent dragbar
C^+Shift+T Open new tab
C^+Shift+PgUp Switch between tabs, PgDown in reverse order
C^+Shift+W Close the current terminal.
C^+Shift+Q Quit terminator
C^+Plus (+) Increase font size. Note: this may require you to press shift, depending on your keyboard
C^+Minus(-) Decrease font size. Note: this may require you to press shift
C^+Zero Restore font size to original setting.
Super+G Group all
Super+Shift+G Ungroup all
References