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:
- Run the Linux distribution.
- Run File Explorer from Linux distribution.
- Manipulate files inside Linux distribution.
Run the Linux Distribution
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.
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
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.
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.