How can I set starting directory for D: in WSL2?

Viewed 1181

I am using Ubuntu-20.04 WSL2 in Windows 10.

I want to approach D: when I open my terminal, so I added this in my workspace settings.json:

"source": "Windows.Terminal.Wsl",
"colorScheme": "Monokai Night",
"startingDirectory": "\\\\wsl$\\Ubuntu-20.04\\mnt\\d" //added this

But it is not working (this code connected me to default of mnt/c/Users/username).

So I also tried this:

"source": "Windows.Terminal.Wsl",
"colorScheme": "Monokai Night",
"startingDirectory": "\\\\wsl$\\Ubuntu-20.04\\mnt" //added this

It is working.

How can I set starting directory for d?

1 Answers

For mounted directories like D:, setting the mount point like /mnt/d won't work (h/t @Dominique).

  • Either use a Windows-style path (with backslashes escaped):

    "startingDirectory": "D:\\"
    
  • Or use Linux-style slashes in newer versions (slashes do not need to be escaped):

    "startingDirectory": "D:/"
    

    – Requires Windows Terminal 1.11.2421.0 on Windows 10 21H2 or Windows 11


Alternatively, ignore the Windows Terminal settings and just cd at the end of your ~/.bashrc:

cd /mnt/d
Related