Support linux paths for startingDirectory of WSL distros #853

Closed
opened 2026-01-30 22:06:31 +00:00 by claunia · 50 comments
Owner

Originally created by @tackyunicorn on GitHub (May 8, 2019).

Originally assigned to: @DHowett on GitHub.

  • Your Windows build number: Microsoft Windows [Version 10.0.18362.86]

  • What you're doing and what's happening:
    Setting the starting directory for wsl in profiles.json doesn't make it point to the right directory.

  1. Take the config below :-
{
        "startingDirectory": "C:/Users/joshj/AppData/Local/Packages/CanonicalGroupLimited.Ubuntu16.04onWindows_79rhkp1fndgsc/LocalState/rootfs/home/tackyunicorn",
        "guid": "{a2785f8e-72c9-4550-b406-697388644902}",
        "name": "Ubuntu",
        "colorscheme": "MonokaiVivid",
        "historySize": 9001,
        "snapOnInput": true,
        "cursorColor": "#FFFFFF",
        "cursorHeight": 25,
        "cursorShape": "vintage",
        "commandline": "wsl.exe",
        "fontFace": "Inconsolata for Powerline",
        "fontSize": 10,
        "acrylicOpacity": 1,
        "useAcrylic": true,
        "closeOnExit": true,
        "padding": "10, 10, 10, 10",
        "icon": "ms-appdata:///roaming/ubuntu.png"
}

This results in wsl starting up in the root folder
issue1

  1. In this config :-
{
        "startingDirectory": "/home/tackyunicorn",
        "guid": "{a2785f8e-72c9-4550-b406-697388644902}",
        "name": "Ubuntu",
        "colorscheme": "MonokaiVivid",
        "historySize": 9001,
        "snapOnInput": true,
        "cursorColor": "#FFFFFF",
        "cursorHeight": 25,
        "cursorShape": "vintage",
        "commandline": "wsl.exe",
        "fontFace": "Inconsolata for Powerline",
        "fontSize": 10,
        "acrylicOpacity": 1,
        "useAcrylic": true,
        "closeOnExit": true,
        "padding": "10, 10, 10, 10",
        "icon": "ms-appdata:///roaming/ubuntu.png"
}

This results in wsl starting up in the Windows user folder
issue2

  • What's wrong / what should be happening instead:
    The startingDirectory profile setting is not being applied correctly on a wsl profile
Originally created by @tackyunicorn on GitHub (May 8, 2019). Originally assigned to: @DHowett on GitHub. * Your Windows build number: `Microsoft Windows [Version 10.0.18362.86]` * What you're doing and what's happening: Setting the starting directory for wsl in `profiles.json` doesn't make it point to the right directory. 1. Take the config below :- ```json { "startingDirectory": "C:/Users/joshj/AppData/Local/Packages/CanonicalGroupLimited.Ubuntu16.04onWindows_79rhkp1fndgsc/LocalState/rootfs/home/tackyunicorn", "guid": "{a2785f8e-72c9-4550-b406-697388644902}", "name": "Ubuntu", "colorscheme": "MonokaiVivid", "historySize": 9001, "snapOnInput": true, "cursorColor": "#FFFFFF", "cursorHeight": 25, "cursorShape": "vintage", "commandline": "wsl.exe", "fontFace": "Inconsolata for Powerline", "fontSize": 10, "acrylicOpacity": 1, "useAcrylic": true, "closeOnExit": true, "padding": "10, 10, 10, 10", "icon": "ms-appdata:///roaming/ubuntu.png" } ``` This results in wsl starting up in the root folder ![issue1](https://user-images.githubusercontent.com/26558907/57397677-d9179c80-71ea-11e9-9f35-a1176a5368d8.png) 2. In this config :- ```json { "startingDirectory": "/home/tackyunicorn", "guid": "{a2785f8e-72c9-4550-b406-697388644902}", "name": "Ubuntu", "colorscheme": "MonokaiVivid", "historySize": 9001, "snapOnInput": true, "cursorColor": "#FFFFFF", "cursorHeight": 25, "cursorShape": "vintage", "commandline": "wsl.exe", "fontFace": "Inconsolata for Powerline", "fontSize": 10, "acrylicOpacity": 1, "useAcrylic": true, "closeOnExit": true, "padding": "10, 10, 10, 10", "icon": "ms-appdata:///roaming/ubuntu.png" } ``` This results in wsl starting up in the Windows user folder ![issue2](https://user-images.githubusercontent.com/26558907/57398045-ba65d580-71eb-11e9-9109-79a9ad601e12.png) * What's wrong / what should be happening instead: The `startingDirectory` profile setting is not being applied correctly on a wsl profile
Author
Owner

@caksoylar commented on GitHub (May 8, 2019):

it looks like it expects Windows paths but passing the WSL fs paths under AppData directly doesn't work. Using the new UNC path works for me:
"startingDirectory":"//wsl$/Ubuntu/home/cem/src" -> ~/src

So do regular Windows locations:
"startingDirectory":"C:/wd" -> /mnt/c/wd

@caksoylar commented on GitHub (May 8, 2019): it looks like it expects Windows paths but passing the WSL fs paths under AppData directly doesn't work. Using the new UNC path works for me: `"startingDirectory":"//wsl$/Ubuntu/home/cem/src"` -> `~/src` So do regular Windows locations: `"startingDirectory":"C:/wd"` -> `/mnt/c/wd`
Author
Owner

@zadjii-msft commented on GitHub (May 8, 2019):

Hmm. We should maybe add a setting to suggest that the startingDirectory is a wsl path. Right now we're just manually setting the working directory of the client app we're starting, so we'd have to specifically know that the profile was trying to be wsl, and adjust our logic for passing in a working directory.

@zadjii-msft commented on GitHub (May 8, 2019): Hmm. We should maybe add a setting to suggest that the startingDirectory is a wsl path. Right now we're just manually setting the working directory of the client app we're starting, so we'd have to specifically know that the profile was trying to be wsl, and adjust our logic for passing in a working directory.
Author
Owner

@sandeepkv93 commented on GitHub (May 19, 2019):

one easy hack would be inside ~/.bashrc file of wsl, add the line
cd ~

Problem solved.

@sandeepkv93 commented on GitHub (May 19, 2019): one easy hack would be inside `~/.bashrc` file of wsl, add the line `cd ~` Problem solved.
Author
Owner

@DHowett-MSFT commented on GitHub (May 20, 2019):

one easy hack would be inside ~/.bashrc file of wsl, add the line
cd ~

Problem solved.

This is also a great way to get weird and unexpected behaviour in everything else that uses bash on your machine. 😄

@DHowett-MSFT commented on GitHub (May 20, 2019): > one easy hack would be inside `~/.bashrc` file of wsl, add the line > `cd ~` > > Problem solved. This is also a great way to get weird and unexpected behaviour in everything else that uses bash on your machine. :smile:
Author
Owner

@JBanks commented on GitHub (Jun 9, 2019):

This method is a little bit of work. We could parse out the distribution name from the command in the profile so that wsl.exe -d Ubuntu gives us "Ubuntu", and then pass that to Profile::EvaluateStartingDirectory. Then, if it fails, before setting it to %userprofile% we can evaluate \\WSL$\[distributionName][directory] and see if that is a valid directory path.

Or we could make the method a non-static method and draw the value from _commandline.

EDIT: I realize now that this won't work. The P9 server will likely not have been started, and if it had been, won't have all of the distros loaded as available shares under the UNC path.

@JBanks commented on GitHub (Jun 9, 2019): This method is a little bit of work. We could parse out the distribution name from the command in the profile so that `wsl.exe -d Ubuntu` gives us "Ubuntu", and then pass that to `Profile::EvaluateStartingDirectory`. Then, if it fails, before setting it to `%userprofile%` we can evaluate `\\WSL$\[distributionName][directory]` and see if that is a valid directory path. Or we could make the method a non-static method and draw the value from `_commandline`. EDIT: I realize now that this won't work. The P9 server will likely not have been started, and if it had been, won't have all of the distros loaded as available shares under the UNC path.
Author
Owner

@benc-uk commented on GitHub (Jun 22, 2019):

@sandeepkv93 - That hack isn't the best. When working in say VS Code and you want your WSL terminal to open inside your project directory, this will prevent that. Definitely going to cause other problems too

@benc-uk commented on GitHub (Jun 22, 2019): @sandeepkv93 - That hack isn't the best. When working in say VS Code and you want your WSL terminal to open inside your project directory, this will prevent that. Definitely going to cause other problems too
Author
Owner

@jkugiya commented on GitHub (Jun 24, 2019):

My workaround

"commandline" : "wsl.exe ~  -d WLinux"
@jkugiya commented on GitHub (Jun 24, 2019): My workaround ``` "commandline" : "wsl.exe ~ -d WLinux" ```
Author
Owner

@siennathesane commented on GitHub (Aug 30, 2019):

I just edited my /etc/passwd after creating a new user to be my Windows' user's home directory /c/Users/MikeLloyd and set startingDirectory to ~ in my profile.json. It works for me as expected on 18965.1005.

@siennathesane commented on GitHub (Aug 30, 2019): I just edited my `/etc/passwd` after creating a new user to be my Windows' user's home directory `/c/Users/MikeLloyd` and set `startingDirectory` to `~` in my profile.json. It works for me as expected on 18965.1005.
Author
Owner

@nanjj commented on GitHub (Sep 2, 2019):

My workaround

"commandline" : "wsl.exe ~"
@nanjj commented on GitHub (Sep 2, 2019): > My workaround > ``` "commandline" : "wsl.exe ~" ```
Author
Owner

@leolozes commented on GitHub (Oct 29, 2019):

What if I want to set the default directory to a directory in C:?
I tried "commandline" : "wsl.exe /mnt/c/Programming -d Ubuntu-18.04" and other directories, with or without /mnt/c/, with or without singlequotes and no luck.

@leolozes commented on GitHub (Oct 29, 2019): What if I want to set the default directory to a directory in C:? I tried `"commandline" : "wsl.exe /mnt/c/Programming -d Ubuntu-18.04"` and other directories, with or without `/mnt/c/`, with or without singlequotes and no luck.
Author
Owner

@Herohtar commented on GitHub (Nov 3, 2019):

@LeoLozes The second post in this thread shows how to do exactly what you want.

@Herohtar commented on GitHub (Nov 3, 2019): @LeoLozes The second post in this thread shows how to do exactly what you want.
Author
Owner

@anikishov commented on GitHub (Nov 14, 2019):

in my case, it works this way
"startingDirectory": "//wsl$/Ubuntu-18.04/home/username"

@anikishov commented on GitHub (Nov 14, 2019): in my case, it works this way `"startingDirectory": "//wsl$/Ubuntu-18.04/home/username"`
Author
Owner

@pluma commented on GitHub (Dec 13, 2019):

Both the wsl.exe ~ -d <distro> and //wsl$/home/<username> workarounds worked for me, but it would be nice if the startingDirectory were interpreted by WSL rather than Windows. E.g. "startingDirectory": "$HOME/projects" should just work.

@pluma commented on GitHub (Dec 13, 2019): Both the `wsl.exe ~ -d <distro>` and `//wsl$/home/<username>` workarounds worked for me, but it would be nice if the `startingDirectory` were interpreted by WSL rather than Windows. E.g. `"startingDirectory": "$HOME/projects"` should just work.
Author
Owner

@mr-cn commented on GitHub (Jan 24, 2020):

It will be nice if Windows Terminal could convert the path. I followed #1060 expecting to start my wsl quickly, but it doesn't work, because Windows Explorer always pass the original path to Terminal.

@mr-cn commented on GitHub (Jan 24, 2020): It will be nice if Windows Terminal could convert the path. I followed #1060 expecting to start my wsl quickly, but it doesn't work, because Windows Explorer always pass the original path to Terminal.
Author
Owner

@mununki commented on GitHub (Jan 25, 2020):

I fix this issue with

"startingDirectory": "//wsl$/Ubuntu-18.04/home/myname"

in Microsoft Windows [Version 10.0.18363.592], ver 0.8.100910.0

@mununki commented on GitHub (Jan 25, 2020): I fix this issue with `"startingDirectory": "//wsl$/Ubuntu-18.04/home/myname"` in `Microsoft Windows [Version 10.0.18363.592]`, ver `0.8.100910.0`
Author
Owner

@xianleon commented on GitHub (Mar 2, 2020):

My way to always start WSL on $HOME:
Create the link of wt.exe,
C:\Users\YOURNAME\AppData\Local\Microsoft\WindowsApps\wt.exe wsl.exe ~ -d Ubuntu
and just pin it on my start menu, and keep "startingDirectory" in profile as null

If you don't pass the "starting directory" to "wsl.exe", it will always start from your current directory.

@xianleon commented on GitHub (Mar 2, 2020): My way to always start WSL on $HOME: Create the link of wt.exe, C:\Users\YOURNAME\AppData\Local\Microsoft\WindowsApps\wt.exe wsl.exe ~ -d Ubuntu and just pin it on my start menu, and keep "startingDirectory" in profile as null If you don't pass the "starting directory" to "wsl.exe", it will always start from your current directory.
Author
Owner

@baoanhng commented on GitHub (Mar 3, 2020):

My solution is to create a new profile with starting command line wsl.exe ~. Latest version on MS store.

{
            "acrylicOpacity" : 1,
            "closeOnExit" : true,
            "colorScheme" : "Campbell",
            "commandline" : "wsl.exe ~",
            "cursorColor" : "#FFFFFF",
            "cursorShape" : "bar",
            "fontFace" : "Consolas",
            "fontSize" : 12,
            "guid" : "{*********************************}",
            "historySize" : 9001,
            "icon" : "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
            "name" : "Ubuntu home",
            "padding" : "0, 0, 0, 0",
            "snapOnInput" : true,
            "startingDirectory" : "%USERPROFILE%",
            "useAcrylic" : true
},
@baoanhng commented on GitHub (Mar 3, 2020): My solution is to create a new profile with starting command line `wsl.exe ~`. Latest version on MS store. ``` { "acrylicOpacity" : 1, "closeOnExit" : true, "colorScheme" : "Campbell", "commandline" : "wsl.exe ~", "cursorColor" : "#FFFFFF", "cursorShape" : "bar", "fontFace" : "Consolas", "fontSize" : 12, "guid" : "{*********************************}", "historySize" : 9001, "icon" : "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png", "name" : "Ubuntu home", "padding" : "0, 0, 0, 0", "snapOnInput" : true, "startingDirectory" : "%USERPROFILE%", "useAcrylic" : true }, ```
Author
Owner

@troy-mac commented on GitHub (Mar 17, 2020):

Easy fix
"startingDirectory": "//wsl$/Ubuntu/home/",

@troy-mac commented on GitHub (Mar 17, 2020): Easy fix "startingDirectory": "//wsl$/Ubuntu/home/<YOUR USERNAME>",
Author
Owner

@antoineco commented on GitHub (Mar 17, 2020):

@troy-mac that will literally start in the "home" directory, not your home directory. Please see above answers for countless working solutions (example)

@antoineco commented on GitHub (Mar 17, 2020): @troy-mac that will literally start in the "home" directory, not _your_ home directory. Please see above answers for countless working solutions ([example](https://github.com/microsoft/terminal/issues/592#issuecomment-565498910))
Author
Owner

@Acris commented on GitHub (Mar 18, 2020):

I use Ubuntu and my workaround is:
"commandline" : "ubuntu.exe"

@Acris commented on GitHub (Mar 18, 2020): I use Ubuntu and my workaround is: `"commandline" : "ubuntu.exe"`
Author
Owner

@troy-mac commented on GitHub (Apr 5, 2020):

Thanks I figured it out... next thing that needs resolving is the /etc/resolv.conf file getting overwritten. Tried a few work arounds non work

@troy-mac commented on GitHub (Apr 5, 2020): Thanks I figured it out... next thing that needs resolving is the /etc/resolv.conf file getting overwritten. Tried a few work arounds non work
Author
Owner

@mikemklee commented on GitHub (Apr 9, 2020):

How do I start WSL at a specific directory?

For instance, If I want to start at ~/dev what do I write in the commandline property?

I tried "commandline": "wsl.exe ~/dev", but got an error like below:

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

[process exited with code 126]

Edit:
nvm. Figure it out by writing

"startingDirectory":"//wsl$/Ubuntu/home/myname/dev"

@mikemklee commented on GitHub (Apr 9, 2020): How do I start WSL at a specific directory? For instance, If I want to start at `~/dev` what do I write in the `commandline` property? I tried `"commandline": "wsl.exe ~/dev"`, but got an error like below: ``` /bin/bash: /home/myname/dev: Is a directory [process exited with code 126] ``` Edit: nvm. Figure it out by writing `"startingDirectory":"//wsl$/Ubuntu/home/myname/dev"`
Author
Owner

@codinronan commented on GitHub (Apr 26, 2020):

With the latest release a couple of days ago (profile.json renamed to settings.json), startingDirectory now doesn't work at all. Not one single variation in this thread works at all for me, is anyone else seeing the same?

@codinronan commented on GitHub (Apr 26, 2020): With the latest release a couple of days ago (profile.json renamed to settings.json), `startingDirectory` now doesn't work at all. Not one single variation in this thread works at all for me, is anyone else seeing the same?
Author
Owner

@max-arias commented on GitHub (Apr 30, 2020):

Setting startingDirectory worked for me, but it seems that you have to place it in the profile you're using. So for example, Ubuntu:

            {
                "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
                "hidden": false,
                "name": "Ubuntu",
                "source": "Windows.Terminal.Wsl",
		"startingDirectory":"//wsl$/Ubuntu/home/me/dev"
            },
@max-arias commented on GitHub (Apr 30, 2020): Setting `startingDirectory` worked for me, but it seems that you have to place it in the profile you're using. So for example, Ubuntu: ``` { "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}", "hidden": false, "name": "Ubuntu", "source": "Windows.Terminal.Wsl", "startingDirectory":"//wsl$/Ubuntu/home/me/dev" }, ```
Author
Owner

@saadanerdetbare commented on GitHub (May 1, 2020):

I have 4 wsl distros installed, Ubuntu, Debian, Kali-Linux and CentOS. When I use the setting "startingDirectory": "\\\\wsl$\\<distroname>\\home\\jakob" For the most part Debian respect the starting directory but not always, the others do not. However, when I open a second tab with one the other 3 distos they always open in ~ It seems that using "startingDirectory": "//wsl$//<distroname>/home/jakob" makes no difference but using \\ is more reliable

Edit: I am running Insider preview build 19619 and wsl2. It seems that when the VMs is up and running they respect the startingDirectory setting. If the VMs are stopped and has to start when opening a tab they do not.

@saadanerdetbare commented on GitHub (May 1, 2020): I have 4 wsl distros installed, Ubuntu, Debian, Kali-Linux and CentOS. When I use the setting `"startingDirectory": "\\\\wsl$\\<distroname>\\home\\jakob"` For the most part Debian respect the starting directory but not always, the others do not. However, when I open a second tab with one the other 3 distos they always open in ~ It seems that using `"startingDirectory": "//wsl$//<distroname>/home/jakob"` makes no difference but using `\\` is more reliable Edit: I am running Insider preview build 19619 and wsl2. It seems that when the VMs is up and running they respect the startingDirectory setting. If the VMs are stopped and has to start when opening a tab they do not.
Author
Owner

@blacklightpy commented on GitHub (May 15, 2020):

Easy fix
"startingDirectory": "//wsl$/Ubuntu/home/",

I don't even know why they give 👎🏻

It should be /home/username not /home

@blacklightpy commented on GitHub (May 15, 2020): > > Easy fix > > "startingDirectory": "//wsl$/Ubuntu/home/", > > I don't even know why they give 👎🏻 It should be /home/username not /home
Author
Owner

@antoineco commented on GitHub (May 15, 2020):

Just to repeat something that was already said, this is how you set your starting directory for a given WSL instance:

    "profiles": [
        {
            "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
            "hidden": false,
            "name": "Ubuntu",
            "source": "Windows.Terminal.Wsl",
            "fontFace": "Cascadia Code",
            "fontSize": 12,

            // THIS                 vvvvvvvvvvvv
            "commandline": "wsl.exe ~ -d Ubuntu"
        }
    ],

Replace "Ubuntu" with the name of your distro.

@antoineco commented on GitHub (May 15, 2020): Just to repeat something that was [already said](https://github.com/microsoft/terminal/issues/592#issuecomment-504947429), this is how you set your starting directory for a given WSL instance: ```jsonc "profiles": [ { "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}", "hidden": false, "name": "Ubuntu", "source": "Windows.Terminal.Wsl", "fontFace": "Cascadia Code", "fontSize": 12, // THIS vvvvvvvvvvvv "commandline": "wsl.exe ~ -d Ubuntu" } ], ``` Replace "Ubuntu" with the name of your distro.
Author
Owner

@blacklightpy commented on GitHub (May 15, 2020):

I have 4 wsl distros installed, Ubuntu, Debian, Kali-Linux and CentOS. When I use the setting "startingDirectory": "\\\\wsl$\\<distroname>\\home\\jakob" For the most part Debian respect the starting directory but not always, the others do not. However, when I open a second tab with one the other 3 distos they always open in ~ It seems that using "startingDirectory": "//wsl$//<distroname>/home/jakob" makes no difference but using \\ is more reliable

Edit: I am running Insider preview build 19619 and wsl2. It seems that when the VMs is up and running they respect the startingDirectory setting. If the VMs are stopped and has to start when opening a tab they do not.

This is because //wsl$/ folder is not initialized until a wsl instance is started. So the first instance wont start in ~, but the others will start in ~ because the first instance initialized the //wsl$/ folder

@blacklightpy commented on GitHub (May 15, 2020): > I have 4 wsl distros installed, Ubuntu, Debian, Kali-Linux and CentOS. When I use the setting `"startingDirectory": "\\\\wsl$\\<distroname>\\home\\jakob"` For the most part Debian respect the starting directory but not always, the others do not. However, when I open a second tab with one the other 3 distos they always open in ~ It seems that using `"startingDirectory": "//wsl$//<distroname>/home/jakob"` makes no difference but using `\\` is more reliable > > Edit: I am running Insider preview build 19619 and wsl2. It seems that when the VMs is up and running they respect the startingDirectory setting. If the VMs are stopped and has to start when opening a tab they do not. This is because //wsl$/ folder is not initialized until a wsl instance is started. So the first instance wont start in ~, but the others will start in ~ because the first instance initialized the //wsl$/ folder
Author
Owner

@troy-mac commented on GitHub (May 15, 2020):

@troy-mac that will literally start in the "home" directory, not your home directory. Please see above answers for countless working solutions (example)

@antoineco I am using Ubuntu (not sure if that matters) but It does put me in my home directory /home/troymac so for me I get the results I was looking for...

@troy-mac commented on GitHub (May 15, 2020): > @troy-mac that will literally start in the "home" directory, not _your_ home directory. Please see above answers for countless working solutions ([example](https://github.com/microsoft/terminal/issues/592#issuecomment-565498910)) @antoineco I am using Ubuntu (not sure if that matters) but It does put me in _my_ home directory /home/troymac so for me I get the results I was looking for...
Author
Owner

@antoineco commented on GitHub (May 15, 2020):

@troy-mac I just tried on Ubuntu, and it doesn't. You probably have another directive, either in your settings file, or your bashrc file, but this alone does not put you in your home directory.

Anyway, my main point was that we should keep this thread free of erroneous information. A working solution was proposed, let's encourage users to use that instead of sharing inaccurate alternative tricks.

@antoineco commented on GitHub (May 15, 2020): @troy-mac I just tried on Ubuntu, and it doesn't. You probably have another directive, either in your settings file, or your bashrc file, but this alone does _not_ put you in your home directory. Anyway, my main point was that we should keep this thread free of erroneous information. A [working solution was proposed](https://github.com/microsoft/terminal/issues/592#issuecomment-504947429), let's encourage users to use that instead of sharing inaccurate alternative tricks.
Author
Owner

@sanyer commented on GitHub (Jul 16, 2020):

For me (perhaps because of zsh), workaround "commandline": "wsl.exe /mnt/d/workspace -d Debian" doesn't work:

zsh:1: permission denied: /mnt/d/workspace

[process exited with code 126]

but "startingDirectory": "D:/workspace" without any "commandline" works just fine, as was suggested in the very beginning.

@sanyer commented on GitHub (Jul 16, 2020): For me (perhaps because of zsh), [workaround ](https://github.com/microsoft/terminal/issues/592#issuecomment-504947429)`"commandline": "wsl.exe /mnt/d/workspace -d Debian"` doesn't work: ``` zsh:1: permission denied: /mnt/d/workspace [process exited with code 126] ``` but `"startingDirectory": "D:/workspace"` without any `"commandline"` works just fine, as was [suggested ](https://github.com/microsoft/terminal/issues/592#issuecomment-490610943)in the very beginning.
Author
Owner

@DHowett commented on GitHub (Jul 16, 2020):

There no world in which specifying the directory by doing wsl /directory will work. That will always (not just when using zsh!) result in the shell attempting to execute the directory and then exit. That's never what you want.

@DHowett commented on GitHub (Jul 16, 2020): There no world in which specifying the directory by doing `wsl /directory` will work. That will _always_ (not just when using zsh!) result in the shell attempting to _execute the directory_ and then exit. That's never what you want.
Author
Owner

@maximgeerinck commented on GitHub (Sep 8, 2020):

any update on this?

@maximgeerinck commented on GitHub (Sep 8, 2020): any update on this?
Author
Owner

@zadjii-msft commented on GitHub (Sep 8, 2020):

@maximgeerinck Nope. We'll make sure to update this thread when there is. In the meantime, might I recommend the Subscribe button?
image
That way you'll be notified of any updates to this thread, without needlessly pinging everyone on this thread ☺️

@zadjii-msft commented on GitHub (Sep 8, 2020): @maximgeerinck Nope. We'll make sure to update this thread when there is. In the meantime, might I recommend the Subscribe button? ![image](https://user-images.githubusercontent.com/18356694/91237459-5cbb0c80-e700-11ea-9347-b9b1ec2813b1.png) That way you'll be notified of any updates to this thread, without needlessly pinging everyone on this thread ☺️
Author
Owner

@troy-mac commented on GitHub (Oct 2, 2020):

Hi all I know I got a few thumbs down for this suggestion that I posted earlier, but I just installed WSL and Ubuntu-20.04 on a new system and all I did was add the below lines to my settings.json file and it 100% worked for dropping me into my home directory. I am not saying it will work for everyone as I am not sure the thumbs down users actually tested this or not, but it has worked for me on 2 different systems both with Ubuntu-20.04 and 18.04. I think it is the easiest thing to try first and if it does not work for you then try a couple other suggestions on this thread.

"startingDirectory": "//wsl$/Ubuntu-20.04/home/troy-mac"
"startingDirectory": "//wsl$/Ubuntu-18.04/home/troy-mac"

or use @antoineco suggestion which may work all the time...
"commandline": "wsl.exe ~ -d Ubuntu"

@troy-mac commented on GitHub (Oct 2, 2020): Hi all I know I got a few thumbs down for this suggestion that I posted earlier, but I just installed WSL and Ubuntu-20.04 on a new system and all I did was add the below lines to my settings.json file and it 100% worked for dropping me into my home directory. I am not saying it will work for everyone as I am not sure the thumbs down users actually tested this or not, but it has worked for me on 2 different systems both with Ubuntu-20.04 and 18.04. I think it is the easiest thing to try first and if it does not work for you then try a couple other suggestions on this thread. "startingDirectory": "//wsl$/Ubuntu-20.04/home/troy-mac" "startingDirectory": "//wsl$/Ubuntu-18.04/home/troy-mac" or use @antoineco suggestion which may work all the time... "commandline": "wsl.exe ~ -d Ubuntu"
Author
Owner

@antoineco commented on GitHub (Oct 2, 2020):

@troy-mac I'm speaking for myself here, but the thumb down was a way to say "Warning, reader. The solution suggested in this message doesn't work for everyone, please refer to the accepted solution instead". It wasn't an attempt to dismiss you.

Like you said, "commandline": "wsl.exe ~ -d <distro_name>" (https://github.com/microsoft/terminal/issues/592#issuecomment-504947429) works in pretty much any case, so let's make sure this solution is visible to people who go through this issue, instead of trying to come up with new, approximate solutions.

@antoineco commented on GitHub (Oct 2, 2020): @troy-mac I'm speaking for myself here, but the thumb down was a way to say _"Warning, reader. The solution suggested in this message doesn't work for everyone, please refer to the accepted solution instead"_. It wasn't an attempt to dismiss you. Like you said, `"commandline": "wsl.exe ~ -d <distro_name>"` (https://github.com/microsoft/terminal/issues/592#issuecomment-504947429) works in pretty much any case, so let's make sure this solution is visible to people who go through this issue, instead of trying to come up with new, approximate solutions.
Author
Owner

@mslot commented on GitHub (Oct 13, 2020):

When installing Ubuntu, can use

"startingDirectory":"\\\\wsl$\\[DISTRONAME]\\home\\[USERNAME]"

If not certain what [DISTRONAME] is, do:

  1. Win+R
  2. \\wsl$
  3. Hit enter

Now you will get the fileshare in an explorer. Fx

image

Simply follow the path to where you want to start from when opening a new tab in Windows Terminal. Remember:

  1. four back slashes at the start and
  2. two back slashes in between the folder names

Like:
image

when construcing the startingDirectory. Restart Windows Terminal, and you are good to go.

@mslot commented on GitHub (Oct 13, 2020): When installing Ubuntu, can use `"startingDirectory":"\\\\wsl$\\[DISTRONAME]\\home\\[USERNAME]"` If not certain what [DISTRONAME] is, do: 1. Win+R 2. \\\\wsl$ 3. Hit enter Now you will get the fileshare in an explorer. Fx ![image](https://user-images.githubusercontent.com/544655/95830710-62b08f80-0d38-11eb-872e-9b43ca307d32.png) Simply follow the path to where you want to start from when opening a new tab in Windows Terminal. Remember: 1. four back slashes at the start and 2. two back slashes in between the folder names Like: ![image](https://user-images.githubusercontent.com/544655/95830792-84117b80-0d38-11eb-94a7-79b03b004225.png) when construcing the `startingDirectory`. Restart Windows Terminal, and you are good to go.
Author
Owner

@Ratismal commented on GitHub (Jan 21, 2021):

I feel like I must be missing something obvious here. Everything I've read in this issue indicates that if you set your startingDirectory to //wsl$/ubuntu/whatever/path/you/want, it will start in that directory. But that's not the case for me? No matter what I set startingDirectory, it always always takes me to my home directory. This is not what I want.

I've tried making new profiles, and I've tried updating the existing ubuntu profile. I've tried forward slashes, back slashes, ~, everything has the same result. See:
image

Is it intentional that you're essentially locked into starting at the home directory, or am I missing something?

@Ratismal commented on GitHub (Jan 21, 2021): I feel like I must be missing something obvious here. Everything I've read in this issue indicates that if you set your startingDirectory to `//wsl$/ubuntu/whatever/path/you/want`, it will start in that directory. But that's not the case for me? No matter what I set startingDirectory, it always _always_ takes me to my home directory. This is not what I want. I've tried making new profiles, and I've tried updating the existing ubuntu profile. I've tried forward slashes, back slashes, `~`, everything has the same result. See: ![image](https://user-images.githubusercontent.com/1059362/105406381-9594da00-5be9-11eb-9948-0bec6e2bcd1a.png) Is it intentional that you're essentially locked into starting at the home directory, or am I missing something?
Author
Owner

@zadjii-msft commented on GitHub (Jan 21, 2021):

You might need to use backslashes (instead of forward slashes), because it definitely works:

image

Is there anything else in your .bashrc that might be changing directories?

@zadjii-msft commented on GitHub (Jan 21, 2021): You might _need_ to use backslashes (instead of forward slashes), because it definitely works: ![image](https://user-images.githubusercontent.com/18356694/105407821-caa62a00-5bf3-11eb-9557-eac9ae509918.png) Is there anything else in your `.bashrc` that might be changing directories?
Author
Owner

@mariusstrom commented on GitHub (Jan 21, 2021):

I feel like I must be missing something obvious here. Everything I've read in this issue indicates that if you set your startingDirectory to //wsl$/ubuntu/whatever/path/you/want, it will start in that directory. But that's not the case for me? No matter what I set startingDirectory, it always always takes me to my home directory. This is not what I want.

@Ratismal
What's the output of wsl.exe -l? Make sure the startingDirectory path matches the name of the WSL distro from wsl.exe -l exactly. If case sensitivity is required there, I'm guessing yours should be Ubuntu, and not ubuntu. Some distros include the LTS version in the distro name (like you can see in @zadjii-msft's post above with Ubuntu-18.04).

"startingDirectory": "//wsl$/Ubuntu/home/cat/proj"

I think it's case-sensitive to the distro name.

@mariusstrom commented on GitHub (Jan 21, 2021): > I feel like I must be missing something obvious here. Everything I've read in this issue indicates that if you set your startingDirectory to `//wsl$/ubuntu/whatever/path/you/want`, it will start in that directory. But that's not the case for me? No matter what I set startingDirectory, it always _always_ takes me to my home directory. This is not what I want. @Ratismal What's the output of `wsl.exe -l`? Make sure the `startingDirectory` path matches the name of the WSL distro from `wsl.exe -l` exactly. If case sensitivity is required there, I'm guessing yours should be Ubuntu, and not ubuntu. Some distros include the LTS version in the distro name (like you can see in @zadjii-msft's post above with Ubuntu-18.04). ```json "startingDirectory": "//wsl$/Ubuntu/home/cat/proj" ``` I think it's case-sensitive to the distro name.
Author
Owner

@mariusstrom commented on GitHub (Jan 21, 2021):

@zadjii-msft forward slashes unescaped work for me:

image

@mariusstrom commented on GitHub (Jan 21, 2021): @zadjii-msft forward slashes unescaped work for me: ![image](https://user-images.githubusercontent.com/22438813/105410546-ee16a800-5be6-11eb-9519-d00651f1242b.png)
Author
Owner

@Ratismal commented on GitHub (Jan 22, 2021):

@mariusstrom

What's the output of wsl.exe -l? Make sure the startingDirectory path matches the name of the WSL distro from wsl.exe -l exactly. If case sensitivity is required there, I'm guessing yours should be Ubuntu, and not ubuntu.

You were exactly right, thank you! I think there might be a bug somewhere in there, though? Did some experimenting.

  • //wsl$/ubuntu/path/that/does/exist - brings me to my home directory
  • //wsl$/ubuntu/path/that/doesnt/exist - brings me to my home directory in the C: drive
  • //wsl$/Ubuntu/path/that/does/exist - brings me to that directory
  • //wsl$/Ubuntu/path/that/doesnt/exist - brings me to my home directory in the C: drive

I would expect that case sensitivity would cause /ubuntu/ to always bring me back to the home directory on the C: drive, since its an invalid path. But that doesn't seem to be the case. Is that... intended behaviour?

@Ratismal commented on GitHub (Jan 22, 2021): @mariusstrom > What's the output of `wsl.exe -l`? Make sure the `startingDirectory` path matches the name of the WSL distro from `wsl.exe -l` exactly. If case sensitivity is required there, I'm guessing yours should be Ubuntu, and not ubuntu. You were exactly right, thank you! I think there might be a bug somewhere in there, though? Did some experimenting. - `//wsl$/ubuntu/path/that/does/exist` - brings me to my home directory - `//wsl$/ubuntu/path/that/doesnt/exist` - brings me to my home directory in the C: drive - `//wsl$/Ubuntu/path/that/does/exist` - brings me to that directory - `//wsl$/Ubuntu/path/that/doesnt/exist` - brings me to my home directory in the C: drive I would expect that case sensitivity would cause `/ubuntu/` to always bring me back to the home directory on the C: drive, since its an invalid path. But that doesn't seem to be the case. Is that... intended behaviour?
Author
Owner

@zadjii-msft commented on GitHub (Jan 22, 2021):

Frankly, I have no idea how the WSL filesystem driver works. The best place to ask would be over at https://github.com/microsoft/WSL

@zadjii-msft commented on GitHub (Jan 22, 2021): Frankly, I have no idea how the WSL filesystem driver works. The best place to ask would be over at https://github.com/microsoft/WSL
Author
Owner

@stephenmartindale commented on GitHub (Feb 5, 2021):

My workaround

"commandline" : "wsl.exe ~  -d WLinux"

This seems to be the commonly accepted solution but it has one fatal flaw: if you use wsl.exe ~ as the commandline, then the --startingDirectory (or -d) parameter to wt.exe ceases to function, properly.

I use the Windows Subsystem for Linux for spinning up sand-boxes for developer experiments, using wsl.exe --export and --import to load up and pack away these sand-boxes as required. At any given time, my default WSL distribution is the one that contains the tool-chain that I'm currently using for my work. For this reason, I've created a WT profile that always spawns whatever the default WSL distribution happens to be:

            {
                "guid": "{75155ba1-aebb-4196-af68-117807257cff}",
                "commandline": "%systemroot%\\System32\\wsl.exe",
                "name": "Windows Subsystem for Linux",
                "icon": "ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.png",
            },

This works great because I can use commands like wt.exe --profile "{75155ba1-aebb-4196-af68-117807257cff}" --startingDirectory "D:\Project1". However, as soon as I append ~, then ~ overrides any and all paths passed to wt via the --startingDirectory command-line parameter.

Obviously, not appending ~ means that starting this profile without --startingDirectory, from within the Terminal's U.I. for example, opens up the new shell in System32 which is sub-optimal.

@stephenmartindale commented on GitHub (Feb 5, 2021): > My workaround > > ``` > "commandline" : "wsl.exe ~ -d WLinux" > ``` This seems to be the commonly accepted solution but it has one fatal flaw: if you use `wsl.exe ~` as the `commandline`, then the `--startingDirectory` (or `-d`) parameter to `wt.exe` ceases to function, properly. I use the Windows Subsystem for Linux for spinning up sand-boxes for developer experiments, using `wsl.exe --export` and `--import` to load up and pack away these sand-boxes as required. At any given time, my default WSL distribution is the one that contains the tool-chain that I'm currently using for my work. For this reason, I've created a WT profile that always spawns whatever the default WSL distribution happens to be: ``` { "guid": "{75155ba1-aebb-4196-af68-117807257cff}", "commandline": "%systemroot%\\System32\\wsl.exe", "name": "Windows Subsystem for Linux", "icon": "ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.png", }, ``` This works great because I can use commands like `wt.exe --profile "{75155ba1-aebb-4196-af68-117807257cff}" --startingDirectory "D:\Project1"`. However, as soon as I append ` ~`, then `~` overrides any and all paths passed to `wt` via the `--startingDirectory` command-line parameter. Obviously, not appending `~` means that starting this profile *without* `--startingDirectory`, from within the *Terminal*'s U.I. for example, opens up the new shell in `System32` which is sub-optimal.
Author
Owner

@dark-swordsman commented on GitHub (Apr 20, 2021):

Using the new UNC path as suggested by caksoylar worked great for me, but just a note to others that, for example, if you have "Ubuntu", it may not just be "Ubuntu". Mine was actually Ubuntu-20.04.

I was able to confirm this by opening up VSCode and using "reveal in explorer" on a file, to which it then opened \\wsl$\Ubuntu-20.04\....

You can also just do \\wsl$ in the address bar and see it there, I had just forgotten that Windows paths use \, not /, lol.

image

@dark-swordsman commented on GitHub (Apr 20, 2021): Using the new UNC path as suggested by caksoylar worked great for me, but just a note to others that, for example, if you have "Ubuntu", it may not just be "Ubuntu". Mine was actually `Ubuntu-20.04`. I was able to confirm this by opening up VSCode and using "reveal in explorer" on a file, to which it then opened `\\wsl$\Ubuntu-20.04\...`. You can also just do `\\wsl$` in the address bar and see it there, I had just forgotten that Windows paths use `\`, not `/`, lol. ![image](https://user-images.githubusercontent.com/7909209/115314315-2b30fe80-a132-11eb-8091-2c3daabcd801.png)
Author
Owner

@LeaveTheCapital commented on GitHub (May 28, 2021):

for me since version 1.9.1445.0 (preview) this no longer worked

{
"commandline": "wsl.exe ~",
"name": "Ubuntu-20.04",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "/home/henry/source"
}

however this works
{
"name": "Ubuntu-20.04",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "//wsl$/Ubuntu-20.04/home/henry/source"
}

@LeaveTheCapital commented on GitHub (May 28, 2021): for me since version 1.9.1445.0 (preview) this no longer worked { "commandline": "wsl.exe ~", "name": "Ubuntu-20.04", "source": "Windows.Terminal.Wsl", "startingDirectory": "/home/henry/source" } however this works { "name": "Ubuntu-20.04", "source": "Windows.Terminal.Wsl", "startingDirectory": "//wsl$/Ubuntu-20.04/home/henry/source" }
Author
Owner

@saadanerdetbare commented on GitHub (May 28, 2021):

This works for me: cd into the directory where I want to start and type wslpath -w .
Example output: \\wsl.localhost\Ubuntu-20.04\home\bob
Put that in the "startingDirectory": and escape any \ with another \

@saadanerdetbare commented on GitHub (May 28, 2021): This works for me: cd into the directory where I want to start and type `wslpath -w .` Example output: `\\wsl.localhost\Ubuntu-20.04\home\bob` Put that in the `"startingDirectory":` and escape any `\` with another `\`
Author
Owner

@ednl commented on GitHub (Jul 19, 2021):

This is because //wsl$/ folder is not initialized until a wsl instance is started. So the first instance wont start in ~, but the others will start in ~ because the first instance initialized the //wsl$/ folder

Is this still true?? I seems to be, it is for me. So is there no way to always (even the first time) start up a WSL instance in the Linux home directory? That seems really strange, especially in WSL2 where the division between file systems is greater because of performance differences.

@ednl commented on GitHub (Jul 19, 2021): > This is because //wsl$/ folder is not initialized until a wsl instance is started. So the first instance wont start in ~, but the others will start in ~ because the first instance initialized the //wsl$/ folder Is this still true?? I seems to be, it is for me. So is there no way to *always* (even the first time) start up a WSL instance in the Linux home directory? That seems really strange, especially in WSL2 where the division between file systems is greater because of performance differences.
Author
Owner

@ghost commented on GitHub (Aug 31, 2021):

:tada:This issue was addressed in #9223, which has now been successfully released as Windows Terminal Preview v1.11.2421.0.🎉

Handy links:

@ghost commented on GitHub (Aug 31, 2021): :tada:This issue was addressed in #9223, which has now been successfully released as `Windows Terminal Preview v1.11.2421.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v1.11.2421.0) * [Store Download](https://www.microsoft.com/store/apps/9n8g5rfz9xk3?cid=storebadge&ocid=badge)
Author
Owner

@Seefer commented on GitHub (Sep 18, 2021):

one easy hack would be inside ~/.bashrc file of wsl, add the line
cd ~

Problem solved.

I've recently discovered that having cd ~ in the .bashrc or .zshrc file of a Linux distro breaks VS Code's integrated terminal behaviour. With cd ~ in one of these shell script files, if you are in a project folder in VS Code and open the integrated terminal, the terminal directory does not point to the project directory. It always opens at ~ .

Is there some other way via WSL to specify the working directory for the distro instead of it always pointing at /mnt/c/Users/<username>?

@Seefer commented on GitHub (Sep 18, 2021): > one easy hack would be inside `~/.bashrc` file of wsl, add the line > `cd ~` > > Problem solved. I've recently discovered that having `cd ~` in the `.bashrc` or `.zshrc` file of a Linux distro breaks VS Code's integrated terminal behaviour. With `cd ~ ` in one of these shell script files, if you are in a project folder in VS Code and open the integrated terminal, the terminal directory does not point to the project directory. It always opens at `~` . Is there some other way via WSL to specify the working directory for the distro instead of it always pointing at `/mnt/c/Users/<username>`?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#853