Practice
Resources
Contests
Online IDE
New
Free Mock
Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
Scaler
Explore Offerings by SCALER

Before you go!

Take this "Tmux Cheat Sheet" interview guide with you

Tmux Cheat Sheet

Download PDF


Your requested download is ready!
Click here to download.

Introduction

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.

Crack your next tech interview with confidence!
Take a free mock interview, get instant⚡️ feedback and recommendation💡

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:

Ubuntu/Debian

sudo apt-get update 
sudo apt-get install tmux

Fedora

sudo dnf -y install tmux

CentOS 

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:

wsl --install

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

2. Prompt

Command Description
tmux This command is used to connect to a new session.
tmux new -s name This command is used to name the session.
tmux a This command is used to attach a session from the prompt.
tmux ls This command is used to list all sessions from the prompt.
tmux a -t myname This command is used to attach a session from a prompt to a name.
tmux kill-session -t myname This command is used to kill a particular session.
exit This command is used to exit from the current session.

3. Sessions

Command Description
s This command lists the session.
$ This command is used to name a session.
:new This command is used to start a new session.
You can download a PDF version of Tmux Cheat Sheet.

Download PDF


Your requested download is ready!
Click here to download.

4. Windows

Command Description
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

5. Panes

Command Description
Ctrl + b + ; This command is used to toggle the last active pane.
Ctrl + b + % This command is used to split panes with a horizontal layout.
Ctrl + b + " This command is used to split panes with a vertical layout.
Ctrl + b + { This command is used to move the current pane left.
Ctrl + b + } This command is used to move the current pane right.
Ctrl + b + q This command is used to show pane numbers.
Ctrl + b + q 0.....9 This command is used to switch/select pane by number.
Ctrl + b +  z This command is used to toggle pane zoom.
Ctrl + b + ! This command is used to convert a pane into a window.
Ctrl + b + x This command is used to close the current pane.

6. Copy Mode

Command Description
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.

7. Misc

Command Description
Ctrl + b + : This command is used to enter command mode.
: set -g OPTION This command is used to set OPTION for all sessions.
: setw -g OPTION This command is used to set OPTION for all windows.
: set mouse on This command is used to enable mouse mode.

8. Configurations Options

Command Description
setw -g mode-mouse off/on This command is used to configure mouse support - on to enable and off to disable.
set -g mouse-select-pane off/on This command is used to configure mouse support for pane selection - on to enable and off to disable.
set -g mouse-resize-pane off/on This command is used to configure mouse support for resizing pane - on to enable and off to disable.
set -g mouse-select-window off/on This command is used to configure mouse support for window selection - on to enable and off to disable.
set -g default-terminal "screen-256color" This command is used to set the default terminal mode to screen-256color.
setw -g monitor-activity on This command is used to enable monitor activity alerts.
set -g visual-activity on This command is used to enable visual activity alerts.
set -g status-justify center This command is used to apply the center property to the window list.

9. Help

Command Description

$ tmux list-keys Or


: list-keys Or


Ctrl + b + ?

This command will produce a list of key bindings(shortcuts)
$ tmux info Show every session, window, pane, etc...

Conclusion

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

1.

How to create a new tmux session named session_one from the command line.

2.

How to create a new window from the command line.

3.

How to kill the current window from the command line.

4.

How to toggle through default pane layouts through the command line.

5.

How can we resize panes using the command line?
 

6.

How to search for the specific window using the command line.

7.

How can we rename the current window using the command line?

8.

Write the command to list existing tmux sessions from Command-Line.

9.

How to move to a specific pane based on an index using the command line.

10.

How to split windows horizontally and vertically using the command line.

Get Placed at Top Product Companies with Scaler Know More 
Get Placed at Top Product Companies with Scaler Know More 
Get Placed at Top Product Companies with Scaler
Sat transparent 640a34d454880bf68e3bfdf33f2389f2214043f59ad18b4c7f7b114e834fb257.svg

Point markers b3add1cc88e4996b2df6e0aedb9f0d1b65fa73c51b7ada8fbee3895a2aa11802.svg Personalised feedback report with solutions
Point markers b3add1cc88e4996b2df6e0aedb9f0d1b65fa73c51b7ada8fbee3895a2aa11802.svg Real life Interview Questions
Point markers b3add1cc88e4996b2df6e0aedb9f0d1b65fa73c51b7ada8fbee3895a2aa11802.svg Identify exact topics to improve

Your feedback is important to help us improve.
Free Mock Assessment
Fill up the details for personalised experience.
All fields are mandatory
Current Employer *
Enter company name *
Graduation Year *
Select an option *
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
Phone Number *
OTP will be sent to this number for verification
+91 *
+91
Change Number
Phone Number *
OTP will be sent to this number for verification
+91 *
+91
Change Number
Graduation Year *
Graduation Year *
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
*Enter the expected year of graduation if you're student
Current Employer *
Company Name *
Please verify your phone number
Edit
Resend OTP
By clicking on Start Test, I agree to be contacted by Scaler in the future.
Already have an account? Log in
Free Mock Assessment
Instructions from Interviewbit
Start Test