5 Useful Tips for Better Tmux Terminal Sessions

tmux is a terminal multiplexer similar to GNU screen, which is used to create, access, and control multiple terminal sessions from a single console. It is useful for system administrators for running more than one command-line program at the same time.

One useful feature of tmux is that it can be detached from a screen and continue running in the background, then later reattached. In this regard, it allows SSH sessions to remain active even after disconnecting from the console.

Read Also: 10 Cool Command Line Tools for your Linux Terminal

In tmux, a session is a container for individual consoles being managed by tmux. Each session has one or more windows linked to it. And a window fills the entire screen and you may split it into several rectangular panes (either vertically or horizontally), each of which is a separate pseudo terminal.

In this article, we will explain some useful tips for better tmux sessions in Linux.

Configure Terminal to start tmux by default

To configure your terminal to automatically start tmux as default, add the following lines to your ~/.bash_profile shell startup file, just above your aliases section.

if command -v tmux &> /dev/null && [ -z "$TMUX" ]; then
    tmux attach -t default || tmux new -s default

Save the file and close it.

Then close and reopen the terminal to start using tmux by default, every time you open a terminal window.

Give Terminal Session Names

tmux gives a default name for sessions, however, sometimes, this name isn’t descriptive enough. You can give a session a name of your choice.

For example if you are working with multiple data centers, you can name sessions like “datacenter1, datacenter2 etc..”.

$ tmux new -s datacenter1
$ tmux new -s datacenter2

Switch between tmux Terminal Sessions

To easily switch between different tmux sessions, you need to enable completion of sessions names. You can use the tmux completion extension to enable it as shown:

$ cd bin
$ git clone https://github.com/srsudar/tmux-completion.git

Then source the file ~/bin/tmux-completion/tmux in your ~/.bashrc file, by appending the following line in it.

source  ~/bin/tmux-completion/tmux

Save the file and close it.

Then close and reopen your terminal window, next time you enter the following command and press the Tab key, it should show you the possible session names.

$ tmux attach -t
Show tmux Terminal Sessions

Show tmux Terminal Sessions

Use Tmuxinator Session Manager

A session manager programmatically creates tmux workspaces by running a series of commands based on a config. The most widely used tmux session manager is tmuxinator.

Tmuxinator is a utility used to create and manage tmux sessions easily. To use it effectively, you should have a working knowledge of tmux. Importantly, you should understand what windows and panes are in tmux.

Use Zoom to focus on a Single Process

Last but not least, after opening up every panes, you want to focus on a single process, you can zoom the process to fill the entire screen. Simply move to the pane you want to focus on and press Ctrl+b, z (use the same to zoom out).

When you’re finished with the zoom feature, press the same key combo to unzoom the pane.

Read Also: 20 Useful Terminal Emulators for Linux

That’s it! In this article, we have explained some useful tips for better tmux sessions in Linux. You can share more tips with us, or ask questions via the feedback form below.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

2 Responses

  1. TaurohtaR says:

    Thanks for the zooming tip. Learned something new.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.