When I type "bash" to the windows explorer address bar and hit Enter, it opens the shell in that directory. Often I find myself wanting to work on files with windows programs in the working directory I reached through shell. Is there an easy way to open explorer from the location reached through shell?
To open the current directory in Explorer - use the following (WSL sets the Windows path by itself):
You can set alias with
.bashrc for a custom command:
echo 'alias explorer="explorer.exe ."' >> ~/.bashrc source ~/.bashrc
Now just use:
to open the current working directory in Windows Explorer.
Microsoft provides a binary
wslpath for exactly this purpose.
explorer.exe `wslpath -w "$PWD"`
Cribbing from the github issue asking for usage info, there are 4 options -
wslpath usage: -a force result to absolute path format -u translate from a Windows path to a WSL path (default) -w translate from a WSL path to a Windows path -m translate from a WSL path to a Windows path, with ‘/’ instead of ‘\\’ EX: wslpath ‘c:\users’
From a WSL shell prompt, run
explorer.exe "Windows path"
If L: maps to your desired directory (any unused drive letter may be used for this). You can map to network drives within Explorer, or to a local folder with SUBST.
Problem is, your /home/USERNAME/ folder in WSL appears to Windows something like C:\Users\YOURUSERNAME\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\home\tester . You could use SUBST to turn this into a drive letter a la
SUBST L: C:\Users\YOURUSERNAME\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\home\tester then use a relative path from L: for your destination.
Let's say you have a WSL folder
/home/YOURUSERNAME/acme/novelties . You could get close to there with
explorer.exe L: but
explorer.exe L:acme or
explorer.exe acme\novelties will not bring you to where you wish to be, and instead will bring you to your Windows user Documents folder, instead.
I have created a little tool called
eopen to open Explorer easily.
Usage: eopen [options] [file | directory | uri] options: -e, --editor Open the file in text editor ($EOPEN_EDITOR) -n, --new Open the specified directory in new instance of explorer --sudo Use sudo to write the unowned file -v, --version Display the version -h, --help You're looking at it note: The file or the directory allows linux and windows path. (e.g. /etc/hosts, C:/Windows/System32/drivers/etc/hosts) The uri must start with protocol schema. (e.g http:, https:)
And here are another solution. https://github.com/4U6U57/wsl-open
For WSL2 you can access to home directory from windows like this :
Sorry to be late at the party!
Taking the best of partial answers above from @sole-sensei and @laverya, add the following alias to your ~/.bash_aliases (or if for some strange reason you don't want/have a separate aliases file, ~/.bashrc):
alias explorer='explorer.exe `wslpath -w "$PWD"`'
If you don't mind tagging it onto the end (I don't because I like to keep it clean and organized):
echo 'alias explorer="explorer.exe ."' >> ~/.bash_aliases source ~/.bash_aliases
Now if we could just get the new Windows Terminal to support ctrl-C and ctrl-V (right-click?! Really Microsoft?!?) we'd be really set!