Terminal

Updated: 2021-11-19

Shortcuts (Sorted By Function)

  • Ctrl + a - Jump to the start of the line
  • Ctrl + e - Jump to the end of the line
  • Ctrl + f - Move forward a char
  • Ctrl + b - Move back a char
  • Ctrl + xx - Move between EOL and current cursor position

Edit

  • Ctrl + d - Delete character from under the cursor
  • Ctrl + w - Cut word before cursor
  • Ctrl + k - Cut to EOL
  • Ctrl + u - Cut from line start to cursor
  • Ctrl + y - Paste
  • Ctrl + t - move forward character before cursor

Others

  • Ctrl + c - Terminate the command
  • Ctrl + z - Suspend/ Stop the command
  • Ctrl + l - Clear the screen
  • Ctrl + x @ - Show possible hostname completions

Shortcuts (Sorted By Key)

Ctrl

  • Ctrl + a - Jump to the start of the line
  • Ctrl + b - Move back a char
  • Ctrl + c - Terminate the command (SIGINT)
  • Ctrl + d - Delete character from under the cursor
  • Ctrl + w - Delete word before cursor
  • Ctrl + e - Jump to the end of the line
  • Ctrl + f - Move forward a char
  • Ctrl + k - Delete to EOL
  • Ctrl + l - Clear the screen
  • Ctrl + r - Search the history backwards
  • Ctrl + R - Search the history backwards with multi occurrence
  • Ctrl + u - Delete backward from cursor
  • Ctrl + xx - Move between EOL and current cursor position
  • Ctrl + x @ - Show possible hostname completions
  • Ctrl + z - Suspend/ Stop the command (SIGSTP)
  • Ctrl + t - move forward character before cursor
  • Ctrl + \ - if Ctrl-c fails. (SIGQUIT)

Alt

  • Alt + < - Move to the first line in the history
  • Alt + > - Move to the last line in the history
  • Alt + ? - Show current completion list
  • Alt + * - Insert all possible completions
  • Alt + / - Attempt to complete filename
  • Alt + . - Yank last argument to previous command
  • Alt + b - Move backward
  • Alt + c - Capitalize the word
  • Alt + d - Delete word
  • Alt + f - Move forward
  • Alt + l - Make word lowercase
  • Alt + n - Search the history forwards non-incremental
  • Alt + p - Search the history backwards non-incremental
  • Alt + r - Recall command
  • Alt + t - Move words around
  • Alt + u - Make word uppercase
  • Alt + backspace - Delete backward from cursor

Misc

  • TAB TAB - Display all available commands(common)
  • <STRING> TAB TAB - Display all available commands starting with string.
  • / TAB TAB - Show entire directory structure including hidden ones.
  • * TAB TAB - Show only sub-directories inside excluding hidden ones.
  • ~ TAB TAB - Show all present users on system from "/etc/passwd"
  • $ TAB TAB - Show all sys variables
  • @ TAB TAB - Show all entries from "/etc/hosts"
  • = TAB TAB - List output like ls or dir

mosh

mosh + tmux

$ mosh -6 [dev-server-address or ssh alias] -- tmux a

You can create an alias in your bash profile so you don't need to type the above command

alias dev="mosh -6 [dev-server-address or ssh alias] -- tmux a"

Alternative

Eternal Terminal (et) is an alternative to mosh https://github.com/MisterTea/EternalTCP

Installing ET on your client # For mac, the simplest way is to use homebrew:

$ brew install MisterTea/et/et

For Ubuntu, use the ET PPA:

sudo add-apt-repository ppa:jgmath2000/et
sudo apt-get update
sudo apt-get install et

Start et:

et -c="tmux -CC a" domain.com:8080

tmux

Configuration

If you want scrollback support, try iterm + tmux + mosh:

Create or edit ~/.tmux.conf on the server and add the following commands:

new-session
set-option -g mouse on
set -g history-limit 30000

Commands

start new:

tmux

start new with session name:

tmux new -s myname

attach:

tmux a  #  (or at, or attach)

attach to named:

tmux a -t myname

list sessions:

tmux ls

kill session:

tmux kill-session -t myname

Kill all the tmux sessions:

tmux ls | grep : | cut -d. -f1 | awk '{print substr($1, 0, length($1)-1)}' | xargs kill

Cheatsheet

In tmux, hit the prefix ctrl+b and then:

Sessions

:new<CR>  new session
s  list sessions
$  name session

Windows (tabs)

c           new window
,           name window
w           list windows
f           find window
&           kill window
.           move window - prompted for a new number
:movew<CR>  move window to the next unused number

Panes (splits)

%  vertical split
"  horizontal split

o  swap panes
q  show pane numbers
x  kill pane
+  break pane into window (e.g. to select text by mouse to copy)
-  restore pane from window
⍽  space - toggle between layouts

{ Move the current pane left
} Move the current pane right
z toggle pane zoom

Resize Panes

:resize-pane -D (Resizes the current pane down)
:resize-pane -U (Resizes the current pane upward)
:resize-pane -L (Resizes the current pane left)
:resize-pane -R (Resizes the current pane right)
:resize-pane -D 20 (Resizes the current pane down by 20 cells)
:resize-pane -U 20 (Resizes the current pane upward by 20 cells)
:resize-pane -L 20 (Resizes the current pane left by 20 cells)
:resize-pane -R 20 (Resizes the current pane right by 20 cells)
:resize-pane -t 2 20 (Resizes the pane with the id of 2 down by 20 cells)
:resize-pane -t -L 20 (Resizes the pane with the id of 2 left by 20 cells)

Window/pane surgery

:joinp -s :2<CR>  move window 2 into a new pane in the current window
:joinp -t :1<CR>  move the current pane into a new pane in window 1

Misc

d  detach
t  big clock
?  list shortcuts
:  prompt

Other Cheatsheets:

https://gist.github.com/afair/3489752