How to Access Linux Files in a Windows Subsystem for Linux (WSL2) from Windows 10

969
Share:
how-to-access-linux-files-in-a-windows-subsystem-for-linux-wsl2-from-windows-10

When working with Windows Subsystem for Linux 2 (WSL 2), sometimes we need to work with files on our WSL Linux distribution. You may wonder how you can work with files effectively. This includes copying files both to and from Windows Subsystem for Linux distributions. This article will take a look at how to copy files from and to Windows Subsystem for Linux WSL 2 with Windows 10's built-in File Explorer.

As a web developer, sometimes I need to access some files from my Laravel / PHP application inside WSL 2 distribution. To achieve this, usually I do this steps:

  1. Run the Linux distribution.
  2. Run File Explorer from Linux distribution.
  3. Manipulate files inside Linux distribution.

Run the Linux Distribution

Run Ubuntu 20.04 WSL 2


Go to your Start menu and type in your distribution name. In this article I'm using Ubuntu 20.04 as an example. Click or press Enter on it to run it.

Run File Explorer from Linux distribution

Next step is opening File Explorer from Linux distribution. On your Linux distribution's shell, run this command:

$ explorer.exe .

When I'm doing it first time, it feels a little funny. On *nix's world, we never have an exe extension for executable files. To make a file executable we'll just need to change it's permission to executable and we're good.

Note the dot after the command.

Explorer.exe from WSL 2

After typing the command and press enter, a new File Explorer window will opened with your home directory content shown.

Manipulate Files Inside Linux Distribution

Explorer.exe Shown


From here you can access whatever Linux files you would like, just like you would any other file through File Explorer. This includes operations such as: dragging files back and forth to other locations, copy and paste, and even interesting scenarios like using the context menu to open VSCode in a WSL directory.

Final Words

I hope that you now know how to access Linux files inside WSL 2 in Windows 10. If you run into any issues or have any feedback feel free to drop a comment below.

Tags Linux Windows
Share:

1 comment

  1. Hi,

    When trying this, it just opens the explorer on the default "Your PC". Even with Microsoft's suggestion of typing "\\wsl$" in the url field of Explorer, it only returns the message "The device couldn't be access."
    Any idea what's wrong here? Is it a Windows permission thing?

    Dahie

Leave a reply

Your email address will not be published. Required fields are marked *