Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the starting directory of a tmux session?

Tags:

linux

unix

tmux

The directory where you start a tmux session in will be the directory that all new windows will start at.

My question is, how can you change this starting directory without closing your session?

like image 360
Adnan Avatar asked Dec 05 '14 02:12

Adnan


People also ask

How do I change tmux sessions?

We can switch session from within tmux: PREFIX + ( : Switch the attached client to the previous session. PREFIX + ) : Switch attached client to the next session. PREFIX + s : Select session from a list of sessions for the attached client interactively.

Where is tmux session stored?

When we start a new instance of tmux, while a server is running, a new session is created inside the running server. (For Advanced users) You can run multiple tmux servers. See -L flag in the documentation. By default, the tmux server is named “default” and the socket is stored in /tmp.

How do I change my split in tmux?

Switching between panes Alternatively, you can use your arrow keys to navigate to a pane according to your layout. For example, if you've got two open panes divided by a horizontal split, you can press Ctrl+B followed by the Up arrow to switch from the lower pane to the top pane.

How do I get out of tmux session without killing it?

Then type "exit" or Ctrl-d. Note that there is no need for Ctrl-b in this step. Once you type "exit" or Ctrl-d in the last remaining pane, tmux will close. You can also exit tmux by pressing : to go to the bottom bar of the tmux window.


1 Answers

The way to do this is to detach from the session (^b d with the default keybindings) and then specify a different directory when you reattach to it. When attaching to a session, use the -c flag to specify the working directory. Here's an example:

$ tmux list-sessions tmuxwtfbbq: 3 windows (created Tue Apr  5 14:25:48 2016) [190x49] $ tmux attach-session -t tmuxwtfbbq -c /home/chuck/new_default_directory 

This setting will be persisted - after you've reset the working directory, you won't need to keep specifying it every time you reattach to the session.

For the record, I'm on tmux version 2.0 (though I don't think it matters - I couldn't find anything about adding a -c option to the attach-session command in the change logs so I assume it's been there for quite a while).

like image 105
chucksmash Avatar answered Nov 05 '22 14:11

chucksmash