• I need to execute a command by default when tmux start a new session.
  • I need to start by default in a folder when session start.

1 Answer 1


You could use a script to start tmux. Saving the following to a bash script (or whatever shell you are using, remembering to fix the hash-bang (#!)), making it executable and then executing the script will get you a new tmux session with a single window running vim. Adjust the session and window names, and the command to your taste.

tmux new-session -d -s mySession -n myWindow
tmux send-keys -t mySession:myWindow "cd /my/directory" Enter
tmux send-keys -t mySession:myWindow "vim" Enter
tmux attach -t mySession:myWindow
  • 1
    I should credit Greg Hurrell where I originally got this from. Mar 31, 2017 at 11:08
  • I've got error message: duplicate session: mySession
    – SLN
    Feb 15, 2019 at 10:35
  • You probably need to kill the existing session first Feb 17, 2019 at 4:19
  • how do you execute this script?
    – chovy
    Sep 30, 2019 at 20:59
  • After saving it as a file in the current directory (as script-name.sh for example), make it executable (chmod +x script-name.sh), then run the script like this: ./script-name.sh. Oct 1, 2019 at 4:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .