Lädt...

🔧 Tmux and Bash: The Power Duo for Dev Productivity


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

If you're juggling multiple terminal sessions and constantly losing track, tmux is your new best friend. And when you combine tmux with Bash scripts? That's next-level automation.

In this article, we'll explore how tmux works, why it's amazing, and how you can use it with Bash scripts to boost your workflow.

What is tmux?

tmux (Terminal Multiplexer) is a tool that allows you to create, manage, and persist terminal sessions. With tmux, you can:

  • Run multiple terminal sessions in one window (split panes, multiple tabs, etc.)
  • Detach and reattach sessions (close your terminal, log out, and come back later!)
  • Run processes in the background without worrying about disconnects
  • Automate and organize workflows

Think of it as a supercharged tab manager for your terminal.

Installing tmux

If you don’t have tmux installed, you can get it with:

  • Ubuntu/Debian: sudo apt install tmux
  • Mac (Homebrew): brew install tmux
  • Arch Linux: sudo pacman -S tmux
  • CentOS/RHEL: sudo yum install tmux

Once installed, fire it up with:

 tmux

You'll see a new terminal session with a green bar at the bottom. That's tmux in action!

Basic tmux Commands

Here are some must-know tmux commands to get you started:

Command What it does
tmux new -s mysession Create a new session named mysession
tmux ls List all running tmux sessions
tmux attach -t mysession Reattach to a session
tmux detach (Ctrl+b, d) Detach from the session but keep it running
tmux kill-session -t mysession Kill a session
tmux split-window -h Split pane horizontally
tmux split-window -v Split pane vertically
tmux new-window Create a new window
tmux next-window Switch to the next window

To interact with tmux, press Ctrl+b first, followed by the command.

Why Combine Tmux with Bash Scripts?

While tmux is great for managing terminals, pairing it with Bash scripts lets you automate tasks and organize sessions like a pro.

Example 1: Automatically Start a Session with Multiple Panes

Let’s say you frequently SSH into a server, open a logs viewer, start a database service, and run a script. Instead of manually doing this every time, create a script!

#!/bin/bash
tmux new-session -d -s mysession

tmux send-keys -t mysession 'cd /var/logs && tail -f syslog' C-m
tmux split-window -v -t mysession

tmux send-keys -t mysession 'cd ~/my_project && ./run.sh' C-m
tmux attach -t mysession

Save this as start_project.sh, make it executable (chmod +x start_project.sh), and run it whenever you need your workspace ready instantly!

Example 2: Automating a Server Setup

Suppose you regularly set up a development environment with multiple services. Automate it with a tmux script:

#!/bin/bash
tmux new-session -d -s dev

tmux send-keys -t dev 'cd ~/backend && npm start' C-m
tmux split-window -h -t dev

tmux send-keys -t dev 'cd ~/frontend && npm start' C-m
tmux split-window -v -t dev

tmux send-keys -t dev 'docker-compose up' C-m
tmux attach -t dev

Now, whenever you need to spin up your environment, just run ./setup_dev.sh—and you're good to go!

Conclusion

If you're not using tmux yet, you're missing out on a massive productivity boost. It keeps your terminal sessions organized, prevents accidental process terminations, and, when combined with Bash scripts, takes automation to the next level.

So go ahead—install tmux, play around with it, and start scripting your workflows. Once you get the hang of it, you'll wonder how you ever worked without it!

If you are interested in exploring such similar technologies, take a look at LiveAPI.

Its a Super-Convenient tool which you can use to generate Interactive API docs instantly!

You can instantly try it out here!

...

🔧 Tmux and Bash: The Power Duo for Dev Productivity


📈 56.47 Punkte
🔧 Programmierung

🐧 tmuxp 1.12.0 (session manager for tmux) and libtmux 0.12.0 (python API for tmux) released


📈 35.62 Punkte
🐧 Linux Tipps

🐧 The most useful smallest tmux trick: peek() { tmux split-window -p 33 $EDITOR $@ || exit; }


📈 34.48 Punkte
🐧 Linux Tipps

🐧 Managing tmux plugins with tmux plugin manager


📈 34.48 Punkte
🐧 Linux Tipps

🔧 tmux-tilit : better tiling for tmux 🪟🪓


📈 34.48 Punkte
🔧 Programmierung

🐧 The most useful smallest tmux trick: peek() { tmux split-window -p 33 $EDITOR $@ || exit; }


📈 34.48 Punkte
🐧 Linux Tipps

🐧 The most useful smallest tmux trick: peek() { tmux split-window -p 33 $EDITOR $@ || exit; }


📈 34.48 Punkte
🐧 Linux Tipps

🔧 Grok 3: AI Thông Minh Nhất Thế Giới


📈 28.61 Punkte
🔧 Programmierung

🕵️ Kèo Thẻ Phạt Vip66 Là Gì? 3 Lối Đánh Kèo Chậm Mà Chắc


📈 28.61 Punkte
🕵️ Reverse Engineering

🔧 KISS Principle: Giữ Mọi Thứ Đơn Giản Nhất Có Thể


📈 28.61 Punkte
🔧 Programmierung

🔧 Có thể bạn chưa biết (Phần 1)


📈 28.61 Punkte
🔧 Programmierung

🔧 Tìm Hiểu Về RAG: Công Nghệ Đột Phá Đang "Làm Mưa Làm Gió" Trong Thế Giới Chatbot


📈 28.61 Punkte
🔧 Programmierung

🔧 Back to bash: Inception, running bash inside bash


📈 27.98 Punkte
🔧 Programmierung

🎥 Bash Scripting - BASH Scripts For Heavy Commandline Users [Bash Snippets]


📈 27.98 Punkte
🎥 IT Security Video

🎥 Bash Scripting - BASH Scripts For Heavy Commandline Users [Bash Snippets]


📈 27.98 Punkte
🎥 IT Security Video

🐧 niieani/bash-oo-framework: Bash Infinity is a modern boilerplate / framework / standard library for bash


📈 27.98 Punkte
🐧 Linux Tipps

🐧 Tmux copy-paste mode tips and tricks for productivity


📈 27.31 Punkte
🐧 Linux Tipps

🐧 Maximizing productivity with Tmux and Vim integration


📈 27.31 Punkte
🐧 Linux Tipps

🔧 Make Your Tmux Status Line 100% Better With Bash


📈 26.57 Punkte
🔧 Programmierung

📰 Google Meet Meets Duo Meet, With Meet in Duo But Duo Isn't Going Into Meet


📈 25.08 Punkte
📰 IT Security Nachrichten

🎥 Inside the Microsoft Power Platform | Power Apps, Power Automate, Power BI and more


📈 22.31 Punkte
🎥 Video | Youtube

🐧 Writing Bash Scripts that are not only Bash: Checking for Bashisms and testing with Dash


📈 19.79 Punkte
🐧 Linux Tipps

🐧 Simple Bash Prompt – a fast, pretty, extendable and pure bash prompt


📈 19.79 Punkte
🐧 Linux Tipps

📰 Linux bash exit status and how to set exit status in bash


📈 19.79 Punkte
📰 IT Security Nachrichten

📰 Blind Bash - Obfuscate And Protect Your Bash Code


📈 19.79 Punkte
📰 IT Security Nachrichten

matomo