TMUX
tmux is a program that's name is short for "terminal multiplexor". There are two main benefits of using tmux, the first is that it can keep a shell session operating after you disconnect from the machine. So you can keep a job running leave, come back and attach to the tmux session and pick up where you left off. The second is that you can have multiple shells running at the same time. You can have one shell running a job or downloading something that is taking a while, and work on other things in another shell. When you get comfortable enough with the CLI, tmux can even just replace your desktop.
All of the devices in our cluster already have tmux installed. If you are using your own server or desktop, however, you may need to download it. I believe 100% of Linux distributions will have it in their repositories, so you can install it easily:
apt install tmux pacman -S tmux dnf install tmux
All of the above work for any Debian variant, Arch variant, or Red Hat variant.
To start a tmux session, you can simply type 'tmux'. You wont notice a whole lot has changed, but there will be a new bar at the bottom. You can now create new windows and new panes. Most of the controls start with pressing 'ctrl-b' and then a hotkey. Pressing 'ctrl-b' and then " you will split the window in half horizontally, pressing 'ctrl-b' and then % you will split the window vertically, then you can press ctrl-b and then an arrow key to navigate between the different panes. Pressing 'ctrl-b' and then "c" you will create a new window. Then you can navigate between next and previous windows with 'ctrl-b' "n" and 'ctrl-b' "p" respectively.
Now while the above is obviously useful, the real power comes from being able to detach from the session. Press 'ctrl-b' and then 'd' you will be back at the original terminal. But, no worries, you can get back to your previous session with the command 'tmux attach'. If you will have more than one tmux session running, it makes sense to name your session as well. While you are in the tmux session, pressing 'ctrl-b' and then "$" you will be prompted to rename the session. Then when you detach, you can list all active sessions with the command 'tmux list-sessions' then to attach to a specific session, you would just type 'tmux attach sessionname'.
Command Line Commands
Command | Effect |
tmux | Starts a new tmux session |
tmux list-sessions | Lists all of the active tmux sessions |
tmux attach | Attaches to the most recently detached tmux session |
tmux attach sessionname | Attaches to a specific tmux session |
Tmux Internal Commands (after typing 'ctrl-b')
Input | Effect |
---|---|
" | Split current Pane Horizontally |
% | Split current Pane Vertically |
Arrow Key | Navigate Panes within the same window |
c | Create New Window |
n | Next Window |
p | Previous Window |
0-9 | Select Window by number directly |
$ | Rename Current Session |
, | Rename Current Window |
& | Kill the Current Window |
x | Kill the Current Pane |
Knowing everything on this page is more than enough to get you using tmux in a way that improves your productivity in a Linux environment. There is still more that you can play around with and experiment with for the enterprising student. You can always check the man page for most of the documentation. tmux is even customizeable, so for the aspiring hacker, you can look into changing config files and adding more fun OS-like features. This 3-minute video is a very good example