115

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?

wesalius
  • 1,275
  • 2
  • 10
  • 9
  • lets say I navigate in shell to /mnt/c/Users/adam/Dropbox/folder and I want to work in that directory, I would like to open explorer at that exact location – wesalius Jul 13 '18 at 21:24

13 Answers13

168

To open the current directory in Explorer - use the following (WSL sets the Windows path by itself):

explorer.exe .

You can set alias with .bashrc for a custom command:

echo 'alias explorer="explorer.exe ."' >> ~/.bashrc
source ~/.bashrc

Now just use:

explorer 

to open the current working directory in Windows Explorer.

Glorfindel
  • 4,099
Sole Sensei
  • 1,809
  • 11
    This opens explorer to C:\Windows\System32 folder. Am I missing something? – panta82 Mar 23 '19 at 10:15
  • 2
    @panta82, if you run this comand inside linux emulated directory, explorer.exe can't interprete path to it, so it opens default location.

    But in future releases Microsoft team promises to integrate linux directories in to windows explorer, so it possible to start working then.

    – Sole Sensei Mar 26 '19 at 13:35
  • it just opens system32 folder no matter where i open it from unless i'm in mnt/ then it opens correct counter part – Muhammad Umer May 15 '19 at 01:18
  • @Umer, yes thats right, you can't open linux emulated directory, only mounted mnt/. But you can link to /mnt/c/any_win_path with symbol link: ln -s in linux home, then it works inside home. – Sole Sensei May 17 '19 at 13:01
  • 2
    alias explorer='explorer.exe wslpath -w "$PWD"' – Ted Nov 21 '19 at 01:28
  • The comments probably don't reflect current status (2021). WSL open linux emulated directory in explore.exe properly now. wslpath is only required if you need to pass the path around. – Jerry Jun 30 '21 at 17:27
41

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 - -a, -u, -w and -m.

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’
laverya
  • 637
  • is there opposote for wslpath? ex. to pass convert path from windows in wsl? – Psychozoic Feb 19 '19 at 14:22
  • 1
    @Psychozoic that would be wslpath -u to convert from a windows path to a wsl path – laverya Jul 30 '19 at 17:56
  • Nice. So you can create a bash open <path> command by adding the following to ~/.bash_aliases: function open { explorer.exe `wslpath -w "$1"` } – automorphic Oct 05 '20 at 00:49
  • But when do you need this? explorer.exe . also works just fine. – Albert Dec 16 '20 at 12:33
  • Well, at time of answer explorer.exe . did not work just fine. And while it's now magic, other commands will still require the use of wslpath. – laverya Dec 18 '20 at 21:48
31

For WSL2 you can access to home directory from windows like this :

\\wsl$

Sorry to be late at the party!

17

You can use wslview like this to open an explorer instance in CWD

wslview .

It is a feature from wslutilities and comes installed by default in newer Ubuntu WSL distros. It can be installed in almost all other popular distros.

sudhackar
  • 103
trallnag
  • 299
5

I have created a little tool called eopen to open Explorer easily. https://github.com/ko1nksm/eopen

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

4

From a WSL shell prompt, run

explorer.exe "Windows path"

such as

explorer.exe L:

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.

K7AAY
  • 9,631
4

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!

Ted
  • 161
2

Setup by running this command :

echo "alias open='explorer.exe'" >> ~/.bashrc

Usage :

open 'directory name'

While similar to previous answers it allows you to manually define the path which is more usual for command line tools. Also I find this more intuitive and quicker to type than 'explorer'.

Inyoka
  • 121
1

I tend to use the command cmd.exe /c start . when upon you should see file explorer open in the dir you are in.

damo@laptop:/mnt/c/Windows/System32$ pwd
/mnt/c/Windows/System32    
damo@laptop:/mnt/c/Windows/System32$ cmd.exe /c start .
  <opens file explorer in c:\Windows\System32>
damo@laptop:/mnt/c/Windows/System32$ cd ~
damo@laptop:~$ pwd
/home/damo
damo@laptop:~$ cmd.exe /c start .
  <opens file explorer in c:\Windows\System32>
damo@laptop:~$ cd /mnt/c/stuff
damo@laptop:~$ cmd.exe /c start .
  <opens file explorer in c:\stuff>

I set up the following to create an alias alias start='cmd.exe /c start which then allow you to simply run start . from any directory.

Damo
  • 111
1

This is my version of the code

explorer() {
    pwd -P | xargs wslpath -w | sed "s~C:\\\Users\\\User\\\Desktop~d:~" | xargs -0 explorer.exe
}

I use subst drives in Windows. The sed part convert this for you. If you don't use the feature, you can exclude it.

Note: I posted this answer even though there are many already because none of them covers symlink or subst drives.

1

Add this function below to your .bashrc:

e(){
    path=$(wslpath -w "$1")
    /mnt/c/Windows/explorer.exe "$path"
}
Hải Vũ
  • 11
  • 1
  • 1
    Please don't use path as a variable name. In my case it overrode the original PATH on zsh and the shell pretty much unusable after running e – sudhackar Oct 25 '21 at 12:09
0

A note about this explorer.exe . command: Found that it allows writing to home directory only. I wanted to edit some files in /etc/apache2, but it does not allow write there.

So my quick solution was to save to profile folder, then move with sudo mc utility to where I needed it to go.

Giacomo1968
  • 55,001
Peminator
  • 103
  • 1
    This answer might be helpful, but at the end you appended a new question: “ anyone - best simple "ctrl-v, ctrl-c" supporting editor? i fear vim, till now i use mc built in editor” I removed that and sadly I don’t think that can stand alone as a new question because it is an opinion-based software recommendation question. Perhaps you can use Nano? Lots of command line editors out there. – Giacomo1968 Jan 06 '21 at 04:53
0

I had an issue to open windows directory with the explorer.exe command from within wsl shell. The error message is /mnt/c/system32/explorer.exe: permission denied. It turns out that I need to add the following to wsl.config (need sudo vim to edit) and restart:

[interop]
enable = true
appendWindowsPath = true

[filemask] umask = 00

yshk
  • 101