Whats is tmux
https://en.wikipedia.org/wiki/Tmux
tmux is basically an everlasting terminal that does not disappear when you logoff or get disconnected.
Think of it as having an always open SSH session that will never go away unless you chose to close it.
It is the easiest way and in my opinion best way to run commands or command line services that stop when you log off but you need them to keep running. Think something like McMyAdmin as an example.
I have a simple txt file in my home directory that lists things i have running in various places which i update before logging off. It is very easy to forget that you started some server which requires the terminal to remain open in a tmux session, or you left a running process who’s output needs to be checked when completed.
If i write a script that has an long expected run time, i will have this simply echo a line to the text file when it completes, so i login cat the txt file and new entry is there DATE – Script Name – Completed – tmux session name.
This helps me avoid the, what the hell was i doing and what do i need to start / stop etc when coming back after a bit of time.
Shortcuts
tmux commands are bound to a keyboard shortcut by default
They’re accessed by entering a key combination called the prefix and then typing a letter.
For example, if you see prefix + d
below, that means you would first hit (and release) Control + b
and then type d
.
The prefix can also be changed
Session Management
These are your goto commands. Aliassing some of these will make your life very easy. I have tll aliased to “tmux list-sessions” aliased in my bashrc file.
tmux new -s session_name
creates a new tmux session named session_name
tmux attach -t session_name
attaches to an existing tmux session named session_name. i.e. you log back on to the machine and reconnect to the session
tmux switch -t session_name
switches to an existing session named session_name
tmux list-sessions
lists existing tmux sessions. also uses alot until you remember the sessions you create by default. You could also simply create an alias in bash that reconnects you to your primary session.
tmux detach (prefix + d)
detach the currently attached session
Windows
tmux has a tabbed interface, but it calls its tabs “Windows”. To stay organized, rename the windows if you use this. It will make your life easier; tmux new-window (prefix + c)
create a new window
tmux select-window -t :0-9 (prefix + 0-9)
move to the window based on index
tmux rename-window (prefix + ,)
rename the current window
Panes
tmux split-window (prefix + ")
splits the window into two vertical panes
tmux split-window -h (prefix + %)
splits the window into two horizontal panes
tmux swap-pane -[UDLR] (prefix + { or })
swaps pane with another in the specified direction
tmux select-pane -[UDLR]
selects the next pane in the specified direction
tmux select-pane -t :.+
selects the next pane in numerical order
Helpful tmux commands
tmux list-keys
lists out every bound key and the tmux command it runs
tmux list-commands
lists out every tmux command and its arguments
tmux info
lists out every session, window, pane, its pid, etc.
tmux source-file ~/.tmux.conf
reloads the current tmux configuration