How to change the starting directory of a tmux session?

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?

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

To start a new session, in a terminal window type: tmux. Your screen will change and display a status bar at the bottom. In the lower-left, you’ll see the name and number for the window: [0] 0:bash* In the lower-right, the date and time are displayed. Just beside the date and time, you’ll see the logged-in user and host: username@host-server

Chucksmash's answer is a good one, but it can also be achieved without using the session if you like. The command attach-session is also available in the tmux command prompt; and the target session can be specified as the "current" session using a dot.

attach-session -t . -c /path/to/new/directory

First, create a file ‘.tmux.conf’ in the ‘home’ folder. Here, The command ‘ctrl-b’ is replaced with ‘crtl-a’ along with some other changes.

Here's how you can change the tmux session's working directory without detaching the session, and without needing use to ctrl+b.

tmux command-prompt "attach -c %1"

will open a command prompt, then you type the working directory you want ~/my/dir, then press ENTER.

All future new windows will start in the above dir.

Note: attach, attach-session, and a are all aliases for each other.

A tmux session is, put simply, and container for windows and panes. A window contains one or more panes. Each pane and each window are a virtual terminal, it just happens to be that windows can

start new: tmux start new with session name: tmux new -s myname attach: tmux a # (or at, or attach) attach to named: tmux a -t myname list sessions: tmux ls kill session: tmux kill-session -t myname In tmux, hit the prefix ctrl+b and then: Sessions:new<CR> new session s list sessions $ name session Windows (tabs)

sudo apt install tmux Attach and Detach from a tmux Session. When tmux is started it creates a new session with one window and one pane. Start a session: tmux Your terminal window should have a green menu bar at the bottom, similar to the one below: Detach from the session: tmux detach This will return you to the basic terminal.

tmux-session. I wrote a little script to create and fast-switch between different tmux sessions, and thought I'd share it real quick so others can use it too. It's got two composable components you can use in your own stuff: The Script Itself. If I'm not running the right tmux session, I run tmux-session. If I'm not in a tmux client (that is

Comments
  • This question would be more on topic at superuser.com, and this question & answers over at unix.stackexchange.com may help you
  • Below is the quickest way to do it from within the session. :attach-session -c /my/path
  • This was helpful for me. It seems the "current working directory" is associated with that particular attachment to the session (where you were when you ran tmux) and not the tmux session itself. Thanks chucksmash!
  • This also works when starting a new session. tmux new -s foo -c ~/some/path. I'm on version 2.1.
  • You could also do below from within the session. :attach-session -t . -c '#{pane_current_path}'
  • This allows one to add a key-binding to update the working directory, such as using bind -n M-u attach-session -t . -c '#{pane_current_path}' to bind alt-u (without prefix) to such an update.