If I right-click on a folder holding shift it does show open Linux shell here.
But if I am in say D: drive no matter which folder I am in it will always open the Linux shell starting at /mnt/d.

What could be the reason for that?


Likely something in a startup script is interfering, but let's walk through the troubleshooting.

First, let's check the command that Windows is using when you select "Open Linux shell here". In PowerShell:

(Get-ItemProperty -name "(default)" -LiteralPath Registry::HKEY_CLASSES_ROOT\Directory\shell\WSL\command).'(default)'

The result should be wsl.exe --cd "%V", and I'm guessing it is. If not, you can fix that with a registry edit.

But let's try that command from PowerShell as well:

wsl.exe --cd "D:\some directory" (where, obviously, some directory is replaced with something that exists on your drive).

I'm also guessing that this will have the same results for you that the right click did - It will end up in D:\ rather than the desired directory. But if it does work, then we'll need to investigate further on why there's a difference with the right-click Open-with command.

So now, let's see if we can make it work from the CLI. Try:

wsl.exe --cd "D:\some directory" -e bash --noprofile --norc

I'm hoping that works for you. That will indicate the problem is something in your .profile or .bashrc (or another startup script).

If so, see if you can track any startup script customization you've done that might affect the cd. It's possible that the change was made by some installer, as well. Or perhaps even that some distribution's stock startup scripts are a problem. You didn't mention which distro you are using, but things work correctly for me on Ubuntu 20.04.

  • Yeah man!! . That was so cool!! I fixed it. .bashrc file had a line cd /mnt/d . Jan 23 at 13:48
  • I really liked the way you approached this. I want to become good at all this. Is there any book/online courses you recommend? I know these skills cannot be gained directly from a book or course. But the understanding happens over time. Still any recommendations which could improve me in computer science. Thanks a lot Jan 23 at 13:51
  • This doesn't work for me. I have the expected command, and it works for Windows directories properly, but when it is using a folder in WSL, it always goes to the home folder, even when using the --noprofile --norc flags
    – mbomb007
    Mar 3 at 14:36
  • @mbomb007 By "using a folder in WSL", do you mean that the path is somewhere in \\wsl$\distroname\...? Mar 3 at 21:05
  • @Amitwadhwa Apologies for not responding on your question sooner. And thank you! Just asking that question shows you have the desire to make it happen. Short answer here - (1) Fail often :-). Seriously - The more you fail, the more you learn how to identify and more rapidly solve problems in the future. (2) Outline everything. Break your notes down into outline form - IMHO, this helps you develop a habit of breaking down problems into their base parts as well. Happy to discuss further in a chat, if you'd like. Mar 3 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.