AI and VoIP Blog

VOIP | AI | Cloud | Kamailio | Open Source


TMUX: Mastering the Art of Command-Line Efficiency

Introduction

In the world of command-line tools, efficiency and multitasking are paramount. That’s where TMUX, a terminal multiplexer, excels. It allows users to launch multiple terminal windows and switch easily between them, detach them (to keep them running in background), broadcast commands to multiple terminals and much more. This guide aims to introduce TMUX to beginners, providing a comprehensive start to mastering this powerful tool. While initially challenging, practice reveals the ease and speed of shortcuts over mouse clicks, enhancing productivity.

What is TMUX?

TMUX stands for Terminal Multiplexer. It’s a handy tool for users who work extensively with the command line. It allows multiple terminal sessions to be accessed and controlled from a single screen. TMUX can be especially useful for remote work, long-running processes, and managing multiple tasks efficiently.

TMUX combines the functionalities of tools like the Linux screen and Terminator Terminal Emulator, among others, into a single, powerful tool.

Installing TMUX

TMUX is available on most Unix-like operating systems. To install TMUX, use the package manager of your Linux distribution. For example, on Ubuntu or Debian systems, you can install TMUX using:

sudo apt-get install tmux

For Red Hat/CentOS systems, use:

sudo yum install tmux

For macOS, use:

brew install tmux

Windows users can use TMUX with Windows Subsystem for Linux (WSL) or with Cygwin.

Basic Commands

  • Starting TMUX: Simply type tmux in your terminal to start a new session.
  • Creating New Windows: Once inside a TMUX session, you can create a new window by pressing Ctrl + b, then ". (Note: Use the Shift key to press ").
  • Switching Between Windows: To navigate between windows, press Ctrl + b, then use the arrow keys (, , , ).
  • Splitting Windows: You can split windows into panes. For a vertical split, press Ctrl+b followed by %. For a horizontal split, use Ctrl+b followed by ". (Note: Use the Shift key to press ").
  • Detaching and Attaching Sessions: To detach from a session, press Ctrl+b followed by d. To reattach, use tmux attach-session -t [session-name].
  • Broadcast Commands: To broadcast a command to multiple windows, press Ctrl+b followed by : then type the following setw synchronize-panes on, then press Enter.

Advanced Features

  • Session Management: TMUX allows you to manage multiple sessions. This is useful if you want to organize your tasks in separate workspaces.
  • Window & Pane Layouts: TMUX offers several layouts for your panes, which can be adjusted to fit your workflow.
  • Scripting with TMUX: TMUX can be scripted, allowing for automation of tasks and even more powerful usage.

TMUX Shortcuts

ActionKey
Start TMUXtmux
Start a named sessiontmux new -s <session_name>
List TMUX sessionstmux ls
New WindowCmd+b, c
Switch WindowCmd+b, window number
Split Window (Vertical)Cmd+b, %
Split Window (Horizontal)Cmd+b, "
Detach SessionCmd+b, d
Attach Sessiontmux attach-session -t [session-name]
Toggle pane zoomCmd+b, z
tmux shortcuts

For a comprehensive list I would like to mention this PDF
https://comtronic.com.au/blog/wp-content/uploads/comtronic_cheatsheet_tmux_A4.pdf

Pro Tip:

To enable the ability to use the Up arrow key – or Pageup key – for scrolling within a TMUX session, you need to enter Copy Mode. Copy Mode allows you to navigate through the buffer that holds the data for the current window. You can enter Copy Mode by pressing Ctrl+b followed by "[” key. To deactivate Copy Mode just press Ctrl+ c

Very important is to understand the difference between a window and a pane. Windows are like new tabs in a browser while pane is created when a window is split.

Conclusion

TMUX is an incredibly powerful tool for anyone who spends a lot of time in the command line. Its ability to manage multiple tasks, detach and reattach sessions, and customize to fit your needs makes it indispensable for efficient command-line work. As a Senior VoIP Engineer, mastering TMUX can significantly enhance your productivity, especially when managing remote servers or multitasking between different command-line applications.

Happy Multiplexing!

Leave a Reply

Join 48 other subscribers

Akash Gupta
Senior VoIP Engineer and AI Enthusiast



Discover more from AI and VoIP Blog

Subscribe to get the latest posts sent to your email.



Leave a Reply

Discover more from AI and VoIP Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading