51

I know that in MacOS, people use the open . command to open the current directory in a file manager.

Does anybody know the appropriate command to do the same task in Bash on Windows?

pitamer
  • 905
  • 3
  • 15
  • 27
Yass001
  • 693
  • 2
  • 7
  • 9
  • What do you even mean by your question? Imagine, you're looking to some Word document. Then you want to open a Ubuntu app, immediately going to the directory of the Word document, the MS-Word application, ...? – Dominique Jan 08 '19 at 15:20

16 Answers16

88

On Windows with Git Bash, just type:

start .

it will open the current directory in the file explorer.

pitamer
  • 905
  • 3
  • 15
  • 27
Jakegarbo
  • 1,201
  • 10
  • 20
34

You can now call explorer.exe from the bash subsystem. I've set up an alias to use it. I've added the copy to clipboard alias as well for good measure.

Alias:

alias open="explorer.exe"
alias pbcopy="clip.exe"

Example:

cat ~/.ssh/id_rsa.pub | pbcopy
open .
open "D:\\Dir"

The open alias plays well with ., but you'll need to pass it the Windows path if you want to specify a directory.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
8

Right now Microsoft don't recommend to mix Windows explorer with the bash shell. In latest win10 Insider builds you could use from bash something like this

cmd.exe /c start .

If you are using Win10 Anniversary Edition you could try installing a Desktop Environment. Start reading this https://github.com/microsoft/bashonwindows/issues/637 After that you could open a window with the present folder content with

gnome-open .
onoma
  • 1,407
  • 14
  • 8
  • it seems that cmd.exe (or any other windows .exe file) cannot be executed from WSL bash, did you actually test this, or are you guessing? When I enter "cmd.exe /c start ." I get "Exec format error". – philwalk Dec 01 '16 at 21:46
  • I just tested on latest insider build 14971 and it works but it always opens C:\Windows\System32 folder. – onoma Dec 07 '16 at 14:33
6

I'm using this function:

open()
{
    explorer.exe  `wslpath -w "$1"`
}

So if you are in /mnt/c/Users/ and would like to open that folder, just type open .

wslpath will resolve only paths from the Windows system, be aware. If you are looking to do something like open ~ it will not work, and you will get:

wslpath: /home/my-user: Result not representable

Command usage

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’

A proof that this works:

wsdlpath working

nikoskip
  • 1,860
  • 1
  • 21
  • 38
5

You Can Use the following command: explorer .

kuroyza
  • 332
  • 1
  • 5
  • 12
3

I have added

alias open='explorer.exe  `wslpath -w "$1"`'

to the .bashrc file

opens current folder when typed open

I'm using windows ubuntu subsystem.

2

This command should do it:

$ explorer
Adam Starrh
  • 6,428
  • 8
  • 50
  • 89
rrmikhail
  • 21
  • 1
2

try this

$ explorer .

This will work on bash command in windows. I was using R studio and was able to open the directory.

Aman Bagrecha
  • 406
  • 4
  • 9
1

If start . doesn't work for you, it's essentially the same as running explorer.exe . so you can create an alias for it which is what I did.

alias start="explorer.exe"

Side note: Another useful one to have is BROWSER. explorer.exe is capable of starting your default web browser. This comes in handy when you run scripts that open a web browser like starting a React.js development server.

export BROWSER="explorer.exe"
Damian Rivas
  • 309
  • 3
  • 13
1

start . - this is the equivalent of open . in bash

roy
  • 81
  • 1
  • 7
0

To work in all type of paths (Windows-Style and Linux-Style), do as following (the answer of mine to my own question on SU):

(Here my challenge was how I could open Explorer in current working directory with Linux-Style path for view purposes, if you are going into modification or do something else other than just viewing, this is at your own risk, please also read Do not change Linux files using Windows apps and tools):

explorer.exe "C:\Users\userNmae\AppData\Local\Lxss$(sed 's:/:\\:g' <<<"$PWD")"

this will open the Explorer exactly in your working directory. The only thing you need is now define a function to get it to work. You can add this into your .bashrc and source it or re-open Bash.

xplor(){ 
    explorer.exe "C:\Users\userName\AppData\Local\Lxss$(sed 's:/:\\:g' <<<"$PWD")";
 }

Note: Replace userName with your Windows User account name there.

αғsнιη
  • 2,627
  • 2
  • 25
  • 38
0

In WSL2 it looks like the open command is now doing what start does in Windows command. I just put an alias in my .bashrc

start="open"

Now you can do either start . or open . depending on your preferences.

Richard Edwards
  • 1,379
  • 1
  • 17
  • 30
0

Using the MINGW64 shell that comes with Git for Windows, I created these functions in my .profile:

function towinpath {
    { cd "$1" && pwd -W; } | sed 's|/|\\|g'
}

function open {
    path_to_open=""

    if [ -f "$1" ]; then
        filename=$(basename "$1")
        win_dirname=$(towinpath "$(dirname "$1")")
        path_to_open="$win_dirname\\$filename"
    elif [ -d "$1" ]; then
        path_to_open=$(towinpath "$1")
    else
        # Take our chances with windows explorer ...
        path_to_open="$1"
    fi

    if [ -z "$path_to_open" ]; then
        echo "Failed to open $1"
    else
        explorer "$path_to_open"
    fi
}

This seems to work with just about everything you can throw at Windows File Explorer:

open .                         # Opens the current directory
open ../                       # Opens the directory above this one
open /c/Windows                # Opens C:\Windows
open ~/AppData                 # Opens my AppData folder
open ~/*.csv                   # Opens the first CSV file in my home directory in Excel
open https://stackoverflow.com # Opens StackOverflow in my browser!

# Opens paths with spaces in them too:
open /c/Program\ Files/Sublime\ Text\ 3/sublime_text.exe
open '/c/Program Files/Sublime Text 3/sublime_text.exe'
HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
0

To open the current directory via windows subsystem for linux (WSL) use :

 $ explorer.exe .
Paddymac
  • 377
  • 1
  • 3
  • 19
0

The easiest way is to edit .bash_aliases

nano ~/.bash_aliases
# add
alias open='explorer.exe $1'
# save and close: cltr-s, cltr-x
source ~/.bash_aliases

Now, we can use: open . or open documents

Prayson W. Daniel
  • 14,191
  • 4
  • 51
  • 57
0

Opening Windows Terminal in a directory and typing start bash will open a bash terminal in that directory.