Learning coding means GreatToCode Be more than a Coder ! Greattocode , Join GreatToCode Community,1000+ Students Trusted On Us .If You want to learn coding, Then GreatToCode Help You.No matter what It Takes !


CODE YOUR WAY TO A MORE FULFILLING And HIGHER PAYING CAREER IN TECH, START CODING FOR FREE Camp With GreatToCode - Join the Thousands learning to code with GreatToCode
Interactive online coding classes for at-home learning with GreatToCode . Try ₹Free Per Month Coding Classes With The Top Teachers . Tmux Tutorial: Basics to Advanced

Tmux Tutorial: Basics to Advanced

 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.

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

CommandDescription
tmuxThis command is used to connect to a new session.
tmux new -s nameThis command is used to name the session.
tmux aThis command is used to attach a session from the prompt.
tmux lsThis command is used to list all sessions from the prompt.
tmux a -t mynameThis command is used to attach a session from a prompt to a name.
tmux kill-session -t mynameThis command is used to kill a particular session.
exitThis command is used to exit from the current session.

3. Sessions

CommandDescription
sThis command lists the session.
$This command is used to name a session.
:newThis command is used to start a new session.

4. Windows

CommandDescription
cThis command creates a new window
wThis command is used to list all windows
nThis command is used to go to the next window
pThis command is used to go to the previous window
fThis 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

CommandDescription
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 + qThis command is used to show pane numbers.
Ctrl + b + q 0.....9This command is used to switch/select pane by number.
Ctrl + b +  zThis command is used to toggle pane zoom.
Ctrl + b + !This command is used to convert a pane into a window.
Ctrl + b + xThis command is used to close the current pane.

6. Copy Mode

CommandDescription
Ctrl + b + [This command is used to enter copy mode.
Ctrl + b + PgUpThis command is used to enter copy mode and scroll one page up.
qThis command is used to quit the mode.
gThis command is used to go to the top line.
GThis 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.
hThis command is used to move the cursor left.
jThis command is used to move the cursor down.
kThis command is used to move the cursor up.
lThis command is used to move the cursor right.
wThis command is used to move the cursor forward one word at a time.
bThis 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.
nThis command is used for the next keyword occurrence.
NThis command is used for previous keyword occurrence.
SpacebarThis command is used to start the selection.
EscThis command is used to clear the selection.
EnterThis command is used to copy the selection.
Ctrl + b + ]This command is used to paste the contents of buffer_0.
: capture-paneThis command is used to copy the entire visible contents of the pane to a buffer.
: list-buffersThis command is used to show all buffers.

7. Misc

CommandDescription
Ctrl + b + :This command is used to enter command mode.
: set -g OPTIONThis command is used to set OPTION for all sessions.
: setw -g OPTIONThis command is used to set OPTION for all windows.
: set mouse onThis command is used to enable mouse mode.

8. Configurations Options

CommandDescription
setw -g mode-mouse off/onThis command is used to configure mouse support - on to enable and off to disable.
set -g mouse-select-pane off/onThis command is used to configure mouse support for pane selection - on to enable and off to disable.
set -g mouse-resize-pane off/onThis command is used to configure mouse support for resizing pane - on to enable and off to disable.
set -g mouse-select-window off/onThis 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 onThis command is used to enable monitor activity alerts.
set -g visual-activity onThis command is used to enable visual activity alerts.
set -g status-justify centerThis command is used to apply the center property to the window list.

9. Help

CommandDescription

$ tmux list-keys Or


: list-keys Or


Ctrl + b + ?

This command will produce a list of key bindings(shortcuts)
$ tmux infoShow 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.


Post a Comment

0 Comments

•Give The opportunity to your child with GreatToCode Kid's • Online Coding Classes for Your Kid • Introduce Your kid To the world's of coding
•Fuel You Career with our 100+ Hiring Partners, Advance Your Career in Tech with GreatToCode. •Join The Largest Tech and coding Community and Fast Forward Your career with GreatToCode. •10000+ Learner's+ 90 % placement Guarantee. • Learning Coding is Better with the GreatToCode community .
•Greattocode Kid's •GreatToCode Career •GreatToCode Interview •GreatToCode Professional •GreatToCode for schools •GreatToCode For colleges •GreatToCods For Businesses.
Are you ready to join the millions of people learning to code? GreatToCode Pass is your one-stop-shop to get access to 1000+ courses, top-notch support, and successful job placement. What are you waiting for? Sign up now and get your future in motion with GreatToCode Pass.