I have tried the answers posted before me but it is cryptic to me. So I decided to figure out a simpler solution with less parameters.
I got a cheat sheet from the web. Here is a good example
Some commands that I use on daily basis are:
- create new TMUX session
tmux new -s SESSIONNAME
- to list session
tmux ls
- to attach existing session to the terminal
tmux a -t SESSIONNAME
- to kill the session
tmux kill-session -t SESSIONNAME
- send key to an existing session
tmux send-keys -t SESSIONNAME "cd /pathname/"
Here is an example of how one can interact with an existing session.
# create two new sessions SES1 and SES2 and detach them.(-d -s is important)
tmux new-session -d -s SES1
tmux new-session -d -s SES2
# let us send some commands to the other session (Python for example)
tmux send-keys -t SES1 "ipython3" C-m
tmux send-keys -t SES1 "from numpy import zeros" C-m
tmux send-keys -t SES1 "a = zeros((10,10))" C-m
Now If you open SES1 in the new terminal window you will see ipython running and two commands executed.
$ ipython3
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from numpy import zeros
In [2]: a = zeros((10,10))
In [3]:
Method 1: This is my favorite and I have been extensively using it.
create file nano ~/.tmux.conf
content of the file
#TMUX start-up script
new-session -d -s SES3
set -g status off #NOTE: this will disable the status bar(green text in the bottom. Personally, I like it there.
send-keys -t SES3 "ipython3" C-m
send-keys -t SES3 "from numpy import zeros" C-m
send-keys -t SES3 "a = zeros((10,10))" C-m
Method 2:
The next step would be to create a script and run it on start-up. See this for example
create a file tmux_startup in /etc/init.d/.
sudo nano /etc/init.d/tmux_startup
file example
#!/bin/bash
# chkconfig: 2345 20 80
# description: Description comes here.... tmux script runs on startup.
tmux new-session -d -s SES1
tmux new-session -d -s SES2
tmux send-keys -t SES1 "ipython3" C-m
tmux send-keys -t SES1 "from numpy import zeros" C-m
tmux send-keys -t SES1 "a = zeros((10,10))" C-m
When you boot your system you should see the sessions you created.
$ tmux ls