WSL open at specific directory

Viewed 1738

I am trying to open up a terminal in a WSL.

I know I can open it up at the root by doing wsl.exe ~, but is there a way I can open it up at a specific folder?

For instance, I have a directory at ~/Dev, so I want to open up WSL at that location.

When I try wsl.exe ~/Dev, I get the following error

/bin/bash: /home/myname/Dev: Is a directory

[process exited with code 126]

Is there a way around this?

2 Answers

How about this? C:\Users is specified folder in this case.

cmd /k "cd C:\Users && wsl"

Given the Command Reference for Windows Subsystem for Linux I don't think this is possible:

  • Launching without parameters launches a shell in the current directory
  • ~ is a special parameter telling wsl to launch the shell in the uses home directory
  • Any other parameter(s) then ~ are treated as a command that will be executed inside wsl and its output returned to the current shell

It is however possible to customize the home directory of the user using usermod, but it is not technically an answer to your question

Related