How do I access tmux session after I leave it?
I want to see what is going on in one session I created.
As far as I know, you can view your tmux
sessions list by using
tmux list-sessions
to see what sessions are currently running on tmux
.
To actually see what is running in those sessions you have to attach to the particular session, to do this you have two options (from experience).
If you are not currently running a
tmux
session (or not currently intmux
session) you attach by runningtmux attach -t n
(where -t stands for target session and n for that session number).If you are running inside another tmux session you'll get an error trying to connect to another session so the simplest way to see what's running there is to use the
tmux list-windows -a
command then move whatever pane/window you have the task running in.
Moving a window
Using tmux move-window -s n1 -t n2
(-s == source window, -t == target window where the source window will attach to. n1 == number of the window you want to move and n2 is number of the window you are moving to).
Format
The n1 & n2 numbers are ordered/formatted as sessionNumb:windowNumb
.
So first session in first window will be 0:1, and second session in first window will be 1:1.
Note: n2 has to be an available session with a not yet created window. If you move a window to an already created window you will get an error saying "Target window is not empty" and moving to uncreated session will give error "can't find session n".
Moving a pane
Sometimes in one window you might have many panes and you only need to move one pane, this is helpful if you only need that one pane to move inside your current window (as you can't move a window inside another window).
You use almost similar syntax with moving a window but you do tmux move-pane -s *n1* -t *n2*
.
Where n1 now is formatted as sessionNumb:windowNumb.paneNumb
and so is n2.
Examples
After tmux list-windows -a
you will have something like this
0:1: Project- (4 panes) [177x48]
0:2: Mirror (3 panes) [177x48]
0:3: Chat! (1 panes) [177x48]
0:4: ssh* (1 panes) [177x48]
1:1: zsh (2 panes) [176x45]
1:2: zsh* (1 panes) [176x45]
1:3: zsh- (1 panes) [176x45]
Now, moving the window "Chat" from first session to my second session I'll have to run tmux move-window -s 0:3 -t 1:4
(remember can't move window to an already created window).
Moving a pane
If you only need to move a pane then you need to do tmux list-panes -a
or if you already know the window it is from, you can tmux list-panes -t 0:1
See format explanations above.
Result comes showing session 0 window 1 (-s 0:1) has these panes.
1: [177x34] [history 3/10000, 4119 bytes] %7 (active)
2: [88x13] [history 541/10000, 231972 bytes] %8
3: [88x13] [history 2/10000, 1541 bytes] %9
which is just not acceptable, but if you need to see more information so you can know which pane you really need you can do
tmux list-panes -F "#{pane_current_command}" -t 0:1
Which will display current running commands at each pane.
In my case
vim
zsh
python (sadly it's running `ranger`)
So after identifying which pane you want (say the vim one) you need to move it.
tmux move-pane -s 0:1.1 -t 1:1.2
to move to a specific pane in this case 2
If you have only one pane in the target window you can tmux move-pane -s 0:1.1 -t 1:1.
no target pane, and it'll still work.
Following the answer above, you can try:
tmux ls
to get the session number. And then
tmux attach-session -t <session_number>