Tmux

Using tmux

What is tmux?

tmux (terminal multiplexer) is a powerful tool that allows you to manage multiple terminal sessions from a single screen. It is especially useful when working on remote servers over SSH, as it allows you to keep processes running in the background, even if your SSH connection drops. With tmux, you can easily detach from a session and reattach to it later, picking up right where you left off.

In this guide, we will walk you through the steps to create a new tmux session, run a Python script, and check its output without having to keep the terminal window open.

Step 1: Check for Existing tmux Sessions

Check if there are any existing tmux sessions:

tmux ls

Step 2: Kill an Existing tmux Session

If you need to kill an existing tmux session, use:

tmux kill-session -t session_name

Example:

tmux kill-session -t mysession

Step 3: Create a New tmux Session

Create a new tmux session with a specific name:

tmux new -s session_name

Example:

tmux new -s my_testing_session

This opens a new window within tmux.

Step 4: Run Your Python Script

Run your Python script inside the new tmux session:

python3 Testing_ssh.py

You should see the output appearing. Now press Ctrl + B then D to detach from the session.

Step 5: Check the Output

In a new terminal or SSH session, navigate to your script's directory and use the following command to check the output:

tail -f output.txt

You can now close the terminal and check the output file after some time.

If you have any questions, feel free to write them in the comment section.

Happy Coding!

#tmux #terminal #linux #ssh #remotework #python #scripting

Comments