The Windows Subsystem for Linux (WSL) is a wonderful thing. Being able to open up a terminal prompt and compile some C code without needing to deal with MinGW or a booting up a full-blown virtual machine is awesome. But how do you access the home folder from Windows Explorer? You could drill down the installation path of the WSL distribution in question, but if you’re running Windows 10 version 1903, there’s an easier way:
cd explorer.exe .
Boom. That’ll open up an Explorer window directly to your WSL home folder. If you look at the address bar, you’ll see a UNC path like this: \\wsl$\Ubuntu\home\cody. That can be very handy when trying to open something like a local HTML file in your browser (I’m looking at you, fish_config). In fact, you can browse the entire directory structure from a browser with that path.
This isn’t just limited to your home directory, either. Go up a couple of steps and you’re at the root filesystem. Up once more and you’ll see shares representing all the Linux distributions you have installed. The way this is implemented is really interesting, so it’s worth reading the Microsoft announcement post regarding these changes. WSL 2 (which has yet to be officially released) may change things up even more.
Windows Terminal and WSL
Remember how I said the UNC path was handy? If you use the new Windows Terminal, you may have noticed that every time you open a WSL tab, it puts you in your Windows home folder, not the WSL home folder. You can change that by editing the Windows Terminal configuration file (Ctrl+,). In the profile section for your WSL distribution (e.g. Ubuntu), add a JSON key-value pair like this:
"startingDirectory": "//wsl$/Ubuntu/home/cody". (You can use either forward slashes or backslashes, but you’ll need to escape backslashes by doubling them up.)
Once you save the file and open up a new WSL tab, you should see the familiar ~ instead of something like /mnt/c/Users/Cody as your current directory. That’ll save a step every time you start it up (and you do not want to put something like
cd $HOME in your shell startup files; that way madness and chaos lie).
There’s a whole host of useful settings you can take a look at, though you should be somewhat familiar with JSON before changing anything; there’s no plan to add a GUI for configuration any time soon.