Tmux Cheat Sheet
Multiplexing allows you to run multiple programmes in the same terminal, each running its own process, in a single process. This is useful if you need to run a number of tasks in sequence, or if you have a large number of terminal programs to manage. Most of the time, multiplexing is unnecessary, but it can come in handy when you need to run a set of tasks simultaneously. There are many advantages to multiplexing, including the reduction of CPU usage and the use of less RAM, which can make multiplexing more efficient.
What is Tmux?
Tmux is a programme that runs in a terminal and allows multiple terminal programmes to run simultaneously. Each programme within tmux has its own terminal, which is managed by tmux and can be accessed from the single terminal where tmux is running; this is referred to as multiplexing, and tmux is a terminal multiplexer.
Tmux and any programmes running inside it can be disconnected from the terminal where they are running (the outside terminal) and reattached to the same or another terminal. Inside tmux, you can run full-screen interactive programmes like vi (1) or top (1), shells like bash (1) or ksh (1), or any other programme that can run in a Unix terminal.
You can also start a local server within the tmux to manage your react, angular, node .js or any other such framework attached with apache tomcat or any other such application framework. Inside tmux, there is a powerful feature set for accessing, managing, and organizing programmes.
You can have a full-screen instance, a split-screen instance, or an individual window for each task. You can have as many active windows as you want, and you can close any of them at any time. In addition, you can freely move around in the terminal window. Tmux has a lot of flexibility, and you can use it in a lot of different ways. For example, you can use it to run a specific command in a specific terminal window. Or, you can have multiple instances of the same command open in a split-screen view.
We will show you how to use Tmux in this tutorial. It is a programme that allows you to divide a terminal window into multiple ones. So, similar to the GNU screen or Byobu, we can have multiple instances of the terminal open in a single window.
Tmux Tutorial: Basics to Advanced
1. How to Install Tmux?
1. Installing tmux on Linux
On Linux, sudo is used to install tmux, but the commands vary depending on distribution:
sudo apt-get update sudo apt-get install tmux
sudo dnf -y install tmux
sudo yum -y install tmux
2. Installing tmux on Mac
In Mac, tmux can be installed using Homebrew.
What is Homebrew?
Homebrew is a package manager for Mac software. It’s similar to apt-get or yum in Linux environments. It lets you search, discover, and install software with a few clicks. Homebrew is very easy to install and set up. All you have to do is type brew in the terminal and follow the on-screen instructions. You can even set up automatic backups with this tool. It’s that easy!
Once you’ve installed Homebrew, open it up and type in this command:
brew tap caskroom/homebrew-cask
This will add a new category to the Homebrew app called “cask”. Tap is the process of brewing beer and cask is the process of bottling wine. You can also type hb in the terminal to open the Homebrew app and view installed apps. You will see a category called “cask”. It’s full of helpful Mac software. You will see popular Mac apps such as Sierra, Focusrite Scarlett 2i2, and Audacious listed. You can also see more niche apps such as Soundflower and Growl Notifier. There are also more niche homebrew categories such as “yoga” and “electronics”.
Follow the command below to install:
brew install tmux
3. Installing tmux on Windows:
To get Windows to run tmux, you must first install WSL and a Linux distribution.
The first step is to install WSL or its upgraded version, WSL2. To install WSL2, you must be running Windows 10 version 2004 or later (Build 19041 or later) or Windows 11. Older builds of Windows can’t use WSL2, but may be able to manually install WSL.
Almost everything can be done with a single command in Windows PowerShell or command prompt, including enabling required components, downloading the latest Linux kernel, and installing Ubuntu:
The -d flag, followed by the name of the distro, can be used to change the Linux distribution that will be installed. You can see a list of the currently available distributions with this command:
wsl --list --online
If you want to use a distro that isn't listed, you'll have to manually import it.
The following step is to create a username and password for use in Linux. Open your Linux distribution by selecting it from the Start menu.
Once the files have been unpacked, Linux will prompt you to enter a username and password. After you've installed a Linux distribution, the next step is to update your packages:
sudo apt update sudo apt upgrade
Tmux can be installed by running the following Linux command:
sudo apt install tmux
||This command is used to connect to a new session.|
||This command is used to name the session.|
||This command is used to attach a session from the prompt.|
||This command is used to list all sessions from the prompt.|
||This command is used to attach a session from a prompt to a name.|
||This command is used to kill a particular session.|
||This command is used to exit from the current session.|
||This command lists the session.|
||This command is used to name a session.|
||This command is used to start a new session.|
|c||This command creates a new window|
|w||This command is used to list all windows|
|n||This command is used to go to the next window|
|p||This command is used to go to the previous window|
|f||This command is used to find a particular window|
|,||This command is used to name a window|
|&||This command is used to kill a particular window|
||This command is used to toggle the last active pane.|
||This command is used to split panes with a horizontal layout.|
||This command is used to split panes with a vertical layout.|
||This command is used to move the current pane left.|
||This command is used to move the current pane right.|
||This command is used to show pane numbers.|
||This command is used to switch/select pane by number.|
||This command is used to toggle pane zoom.|
||This command is used to convert a pane into a window.|
||This command is used to close the current pane.|
6. Copy Mode
|Ctrl + b + [||This command is used to enter copy mode.|
|Ctrl + b + PgUp||This command is used to enter copy mode and scroll one page up.|
|q||This command is used to quit the mode.|
|g||This command is used to go to the top line.|
|G||This command is used to go to the bottom line.|
|⬆ (Up arrow key)||This command is used to scroll up.|
|⬇ (Down arrow key)||This command is used to scroll down.|
|h||This command is used to move the cursor left.|
|j||This command is used to move the cursor down.|
|k||This command is used to move the cursor up.|
|l||This command is used to move the cursor right.|
|w||This command is used to move the cursor forward one word at a time.|
|b||This command is used to move the cursor backward one word at a time.|
|/||This command is used to search forward.|
|?||This command is used to search backwards.|
|n||This command is used for the next keyword occurrence.|
|N||This command is used for previous keyword occurrence.|
|Spacebar||This command is used to start the selection.|
|Esc||This command is used to clear the selection.|
|Enter||This command is used to copy the selection.|
|Ctrl + b + ]||This command is used to paste the contents of buffer_0.|
|: capture-pane||This command is used to copy the entire visible contents of the pane to a buffer.|
|: list-buffers||This command is used to show all buffers.|
||This command is used to enter command mode.|
||This command is used to set OPTION for all sessions.|
||This command is used to set OPTION for all windows.|
||This command is used to enable mouse mode.|
8. Configurations Options
||This command is used to configure mouse support - on to enable and off to disable.|
||This command is used to configure mouse support for pane selection - on to enable and off to disable.|
||This command is used to configure mouse support for resizing pane - on to enable and off to disable.|
||This command is used to configure mouse support for window selection - on to enable and off to disable.|
||This command is used to set the default terminal mode to screen-256color.|
||This command is used to enable monitor activity alerts.|
||This command is used to enable visual activity alerts.|
||This command is used to apply the center property to the window list.|
||This command will produce a list of key bindings(shortcuts)|
||Show every session, window, pane, etc...|
Tmux is a useful tool that allows us to use the terminal more efficiently by splitting windows and navigating through sessions. This utility is controlled by using commands. We learned the most fundamental and useful ones for daily work.
Multiple Choice Questions
How to create a new tmux session named session_one from the command line.
How to create a new window from the command line.
How to kill the current window from the command line.
How to toggle through default pane layouts through the command line.
How can we resize panes using the command line?
How to search for the specific window using the command line.
How can we rename the current window using the command line?
Write the command to list existing tmux sessions from Command-Line.
How to move to a specific pane based on an index using the command line.
How to split windows horizontally and vertically using the command line.