36

I'm using tmux on EC2 AWS but I want to see what is going on in one session I created.

I use Ctrl+b and then d to leave the session.

3
  • 2
    Did you try tmux attach?
    – Stephen
    Sep 13, 2016 at 19:43
  • after using tmux or when first using it? Sep 13, 2016 at 20:30
  • Normally you luanch tmux, do some stuff, then detach. Then you use tmux attach to get back to that previous session.
    – Stephen
    Sep 13, 2016 at 20:40

4 Answers 4

49

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).

  1. If you are not currently running a tmux session (or not currently in tmux session) you attach by running tmux attach -t n (where -t stands for target session and n for that session number).

  2. 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.

8

Following the answer above, you can try:

tmux ls to get the session number. And then

tmux attach-session -t <session_number>

3

If you have a single tmux session, use:

tmux a

to access it

1

If you'd like to bind that to a key in your shell (to make it seamless when you are outside tmux to pop back in), you could do something like that. This is for zsh.

I would guess only the function and bindkey forms would vary slightly between other shells.

In my ~/.zshrc:

function tmux_last_session(){

    LAST_TMUX_SESSION=$(tmux list-sessions | awk -F ":" '{print$1}' | tail -n1);
    tmux attach -t $LAST_TMUX_SESSION
}
bindkey -s '^s' 'tmux_last_session ^M'

Source it. source ~/.zshrc

Ctrl+s now opens the last detached tmux session.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.