Open a folder in file manager in Win10 WSL while in ubuntu command line?

15,031

Solution 1

Running Nautilus

You can run nautilus from WSL! This will let you manage the Linux file system.

This isn't exactly appropriate for this SE, because it's mostly a windows-related question, but here it is.

Nautilus and many other linux applications can be run on WSL as long as you have a Windows-based X11 server. X11 is the window system most of Linux relies on, but it can be installed on Windows too. X11 runs in client-server mode that decouples the calling client code from the server, so calls out of the WSL are pretty transparent.

Other things you can run with an X11 server include:

  • Sublime
  • Various terminal emulators
  • Calculators
  • Probably other things I haven't tried.

Getting the X11 server

There are a few Windows-based X11 servers. Note that the server works using TCP, and by default it can accept connections from any IP, so you might want to restrict it in your firewall.

I use this one:

https://sourceforge.net/projects/vcxsrv/

Connecting WSL to it

Just put this in your .bashrc/.zshrc file:

export DISPLAY=localhost:0.0

Running nautlius

Don't forget to sudo apt update. Then sudo apt install nautilus. Then

nautilus .

Running explorer.exe

You can invoke any Windows executable from the WSL, including explorer.exe, the Windows file manager. You just need to type its full name (including the extension), and if it's a Win32 executable, it will start.

However, Windows applications run under Windows, not under WSL. They won't see the Linux file system, only the Windows one. While it's true that the Linux file system is mapped to files and folders in the Windows file system, this mapping is more-or-less an implementation detail. It's not recommended to modify the Linux file system from Windows.

You give explorer.exe arguments, but note that you can't give it Linux paths because it's not a Linux application.

There is no command to map a Linux path to the corresponding Windows path and the path is usually pretty ugly. For example, the path to ~/.zshrc might be:

C:\Users\[WINDOWS USERNAME]\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\[LINUX USERNAME]\.zshrc

Solution 2

wslview is the command you are most likely looking for, which is part of the WSL Utilities and pre-installed on most recend Ubuntu for Windows releases.

For example, opening a file explorer for the current directory:

wslview .

Open an html document in a web browser:

wslview readme.html

It functions pretty much like open does on macOS terminals. In fact, I set an alias in my ~/.bashrc file.

# open to match macOS-style use
alias open=/usr/bin/wslview

Which is useful since bash's open doesn't seem to work correctly in WSL2 for me.

Solution 3

Citing the WSL FAQ here:

(WSL) is primarily a tool for developers -- especially web developers and those who work on or with open source projects. This allows those who want/need to use Bash, common Linux tools (sed, awk, etc.) and many Linux-first tools (Ruby, Python, etc.) to use their toolchain on Windows.

WSL is a tool aimed at enabling users who need them to run Bash and core Linux command-line tools on Windows.
WSL does not aim to support GUI desktops or applications (e.g. Gnome, KDE, etc.)

I seriously doubt that Windows lets you open any GUI program at all from WSL, but what you want is a feature of Windows Powershell, see this introduction:

We can call Explorer from within PowerShell by using the command Explorer.

The command to open Explorer in the current directory is: explorer .

Share:
15,031
Patoshi パトシ
Author by

Patoshi パトシ

Updated on September 18, 2022

Comments

  • Patoshi パトシ
    Patoshi パトシ over 1 year

    In Ubuntu I usually do

    nautilus .
    

    to open the current folder in the GUI.
    How would I do this in Win10 WSL? Can you even launch window apps from the WSL command line?

  • NetMage
    NetMage about 6 years
    Your serious doubt was and is wrong.
  • dessert
    dessert about 6 years
    @NetMage Is it? Please add your answer below and I'll be happy to reconsider my answer! OP doesn't ask for Nautilus, but for the correspondent window app, which would be Explorer IIRC – there's still no solution to open that from WSL, and that's what my answer (like the question) aims to.
  • GregRos
    GregRos about 6 years
    @dessert He is referring to the statement "I seriously doubt that Windows lets you open any GUI program at all from WSL". But you can also invoke explorer from the WSL, sort-of. Just type explorer.exe. Of course the program will execute under Windows, not under WSL, but running explorer.exe under Linux doesn't make sense.
  • dessert
    dessert about 6 years
    @GregRos I think you should add that to your answer.
  • NetMage
    NetMage about 6 years
    I don't think OP is interested in the Windows equivalent to Nautilus, "window apps" means X applications as he is used to from Ubuntu.
  • dessert
    dessert about 6 years
    @NetMage Maybe we should ask OP to clarify this, the title says file manager in Win10
  • David A. French
    David A. French over 5 years
    Thank you! This worked great! Very easy and straightforward explanation :)
  • silviubogan
    silviubogan over 4 years
    At the date of this comment, nautilus does not work very well (throws an error when trying to open the Desktop), even when it is run with sudo.
  • GregRos
    GregRos over 4 years
    @silviubogan I routinely use nautilus on WSL. Never had any trouble with it. There is no reason to run it with sudo unless you want admin permissions. You should create another question about it, with the error and the steps you took.
  • João Ramires
    João Ramires over 3 years
    Thank you! That's exactly what I was looking for. Much better than install nautilus + x11