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


The Windows Subsystem for Linux (WSL) is a new Windows 10 feature that enables you to run native Linux command-line tools directly on Windows, alongside your traditional Windows desktop and modern store apps.

When you have Windows Subsystem for Linux (WSL) enabled, you can install WSL distro apps from the Microsoft Store, and export and import WSL distros.

In the past, creating and changing Linux files from Windows resulted in losing files or corrupting data. Making this possible has been a highly requested and long anticipated feature.

Starting with Windows 10 build 18342, Microsoft added the ability for users to access Linux files in a WSL distro from Windows 10. These files can be accessed through the command line, and also Windows apps, like File Explorer, VSCode, etc. can interact with these files.

Linux files for a running WSL distro are located at \\wsl$\<distro_name>.

Known issues

This is a new feature, and some pieces of it may not work perfectly. Here are some known issues that Microsoft wants to make you aware of when using this feature:
  • As of right now, the distros files will only be accessible from Windows when the distro is running (We aim to add support for non-running distros in a future update)
    Since the 9P file server runs inside of each distro, it is only accessible when that distro is running. The team is looking into ways to help resolve this.
  • Accessing Linux files is treated the same as accessing a network resource, and any rules for accessing network resources will still apply
    e.g: When using CMD, cd \\wsl$\Ubuntu\home will not work (as CMD does not support UNC paths as current directories), however copy \\wsl$\Ubuntu\home\somefile.txt C:\dev\ will work
  • The old rules still apply, you should NOT access your Linux files inside of the AppData folder!
    If you try to access your Linux files through your AppData folder, you are bypassing using the 9P server, which means that you will not have access to your Linux files, and you could possibly corrupt your Linux distro.

See also: What’s new for WSL in Windows 10 version 1903

This tutorial will show you how to access all the Linux files of a Windows Subsystem for Linux (WSL) distro from Windows 10.


 CONTENTS:

  • Option One: Access Linux Files in File Explorer from Running WSL Distro
  • Option Two: Access Linux Files of Running WSL Distro in File Explorer
  • Option Three: Access Linux Files of Running WSL Distro in PowerShell





Access WSL Linux Files in Windows 10 OPTION ONE Access WSL Linux Files in Windows 10
Access Linux Files in File Explorer from Running WSL Distro

1. Open the WSL distro (ex: "Ubuntu") you want, and make sure your current folder is your Linux home directory.

2. Copy and paste explorer.exe . in the WSL distro console window, and press Enter. (see screenshot below)

Name:  Access_Linux_files_in_File_Explorer-1.png
Views: 1188
Size:  5.8 KB

3. File Explorer will now open directly to the Linux files for this WSL distro. 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. (see screenshot below)

Name:  Access_Linux_files_in_File_Explorer-2.png
Views: 1203
Size:  34.4 KB






Access WSL Linux Files in Windows 10 OPTION TWO Access WSL Linux Files in Windows 10
Access Linux Files of Running WSL Distro in File Explorer

1. Open File Explorer (Win+E).

2. Click/tap on Linux in the navigation pane of File Explorer, and click/tap on the Distros shortcut. (see screenshot below)

Name:  Access_Linux_files_from_File_Explorer-1.jpg
Views: 1206
Size:  33.7 KB

3. Click/tap on the running WSL distro (ex: "Ubuntu") you want to see the files for. (see screenshot below)

Name:  Access_Linux_files_from_File_Explorer-2.jpg
Views: 1195
Size:  30.6 KB

4. Click/tap on the Home folder. (see screenshot below)

Name:  Access_Linux_files_from_File_Explorer-3.jpg
Views: 1198
Size:  60.7 KB

5. Click/tap on the <username> folder of the user (ex: "brink") you want for this WSL distro (ex: "Ubuntu") . (see screenshot below)

Name:  Access_Linux_files_from_File_Explorer-4.jpg
Views: 1193
Size:  35.4 KB

6. You will now see the Linux files of the user for this WSL distro. 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. (see screenshot below)

Name:  Access_Linux_files_from_File_Explorer-5.jpg
Views: 1195
Size:  39.4 KB






Access WSL Linux Files in Windows 10 OPTION THREE Access WSL Linux Files in Windows 10
Access Linux Files of Running WSL Distro in PowerShell

1. Open a PowerShell or elevated PowerShell.

2. Copy and paste the wsl --list --running into PowerShell, and press Enter to see all currently running WSL distros. Make note of the WSL distro name (ex: "Ubuntu") you want to access files for. (see screenshot below)

3. Type the command below into PowerShell, and press Enter to change to the WSL distro's directory.

cd \\wsl$\<DistributionName>

Substitute <DistributionName> in the command above with the actual WSL distro name (ex: "Ubuntu") you wanted from step 2.

For example: cd \\wsl$\Ubuntu

4. Type ls at the prompt, and press Enter to list the directory above.

5. You can now access your Linux files as usual in PowerShell.

Name:  Access_Linux_files_in_PowerShell.png
Views: 1206
Size:  14.5 KB


That's it,
Shawn


Related Tutorials