Among its numerous advantages, one notable feature is the seamless accessibility of Linux files stored within WSL from the Windows operating system itself.
In this article, you’ll explore various methods of accessing WSL files. This will enable smooth file management and interoperability between Windows and Linux environments.
You will look at both graphical and command-line ways of accessing WSL files inside Windows.
Access WSL files using Windows Explorer
The most basic way of accessing a file on Windows is by launching the Windows File Explorer. The file manager is present on the taskbar, and you can just open it to browse files. Wait! That is for Windows files, but for Linux?
Yes. WSL indeed stores the file inside Windows because it is the host. If you have set up the WSL correctly on Windows, you will see a Penguin icon on your File Explorer.
Just click on it.
You will see the name of the WSL distributions you have installed currently as folders. I have two; an Ubuntu and an OpenSUSE Tumbleweeed.
Double-click on the one you need to access. Now, you are inside the root directory of that system.
Go inside the home → username folder, and there it is.
You are now accessing the home directory of the default user. Double-click on any file to open it on a Windows app. You can see in the screenshot below, I have opened the .bashrc
file on Notepad app.
.bashrc
file in NotepadUse the address bar of Explorer
You can use the address bar of Windows Explorer to go into the WSL folders. For this, click on the to address bar. When it is changed to editing, enter:
\\wsl$
This will bring you to the same folder, where all the WSL distributions are listed as folders. Click on any to enter into it.
💡 Tip: Open the current Linux directory location in Windows
Imagine that you are using Linux through the Windows terminal and you are in a specific directory location. Now, you think it would be better if you could access it in the file explorer.
This is possible and quite easy. Enter the following command on the WSL terminal.
explorer.exe .
Here, the .
refers to the current directory you are in. This means that your current directory will be opened in the Windows file explorer.
Similarly, while inside the WSL, you can specify a directory path to open that folder in Windows Explorer.
As you can see, the mentioned directory is opened in Windows Explorer and you can access the files.
Open a WSL text file in Notepad
While there are terminal-based text editors available in Linux, you may not be comfortable with the idea of editing files in the command line.
Thankfully, you can easily open those Linux text files using Windows’s Notepad.
notepad.exe /path/to/the/file/inside/wsl/distribution
Accessing files between WSL and Windows
As you can easily guess by now, it is possible to access files between WSL and the Windows host operating system.
Here are a few tips on accessing files between Windows and Linux inside WSL.
✋
If you are working on a project inside WSL, be sure to store the files inside the respective WSL system. Similarly, store all the files inside the Windows filesystem if you are working on a project using Windows, you can ensure maximum speed and performance.
Edit Windows files inside WSL
While inside WSL, you can open a file stored on the Windows filesystem using Linux tools like the Nano editor.
For this, we use the Mounted Drive concept.
nano /mnt/c/Users/username/Documents/filename
Here, the /mnt/c
represents the C drive mounted to the WSL. So, what the command actually does is, open the specified file on the location specified in nano editor.
You can use /mnt/d
, if you have a drive located with D:
in Windows.
Copy files between WSL and Windows
Inside the WSL, you can copy a file from WSL to a specified Windows folder. To do that, use the cp
command:
cp /home/$USER/filename /mnt/d/Documents/
This will copy the file called filename
from the home directory of the user to the Documents folder (if exists) on the D drive.
Similarly, if you want to transfer a file from a Windows folder into the WSL system, use:
cp /mnt/d/Documents/filename /home/$USER/
That’s it. You have copied the files.
🚧
Keep caution while managing files between the two operating systems. It can lead to file loses and corruption, if not handled properly.
Wrapping Up
Here, you learned about accessing files between Windows and Linux running inside WSL. The ability to access Linux files easily from Windows is super helpful for Windows users. Let me know if you have any questions.
Have you ever wondered, how to access the windows file system through WSL? If the answer is yes you are in the right place!
Microsoft WSL has given us an incredible way to access the windows file system, you have just to navigate through an exact path to do it. Without further due, let’s dive into the topic.
1. Use the cd command in the Linux terminal.
To access the windows files you have to navigate through /mnt/your_windows_path
cd /mnt/c/Users
**OR**
cd /mnt/d/your_folder/your_folder
Enter fullscreen mode
Exit fullscreen mode
Now you have access to every file in the Linux and Windows file systems.
2. Moving files between the two systems through WSL.
If you want to move files between the two operating systems you can simply use the cp or mv commands.
cp — command for copying files
mv — command for moving files
Use of cp command
cp /mnt/c/file.txt /home/username/Documents
Enter fullscreen mode
Exit fullscreen mode
Use of mv command
mv /mnt/c/file.txt /home/username/Documents
Enter fullscreen mode
Exit fullscreen mode
3. Editing windows files through WSL.
To edit windows files through the Linux terminal using WSL, you have to use any text editor that can be opened in the terminal. One of the most famous text editors is nano. In our example, I am going to use the nano editor.
Type into the terminal nano and the path to the file.
sudo nano /mnt/c/Users/file.txt
Enter fullscreen mode
Exit fullscreen mode
Now you can edit freely files from your terminal.
4. Creating files in windows through WSL.
To create a file in a specific windows directory you have first to navigate to it and then use the touch command to create a file.
touch — a command that creates a file.
!!! The file extension can be anything you want.
cd /mnt/c/Users/Public/Documents/
touch filename.txt
Enter fullscreen mode
Exit fullscreen mode
The file is created and can be opened from both systems.
5. Deleting files from the windows file system through WSL.
To delete windows files using WSL, you have to navigate to the directory where the file lives and use the rm command.
rm — a command that deletes files / directories
cd /mnt/c/Users/Public
sudo rm example_file.jpg
Enter fullscreen mode
Exit fullscreen mode
Congratulations you learned 5 vital skills about working with the Linux terminal. 🎺🎺🎺
If you have any questions, comment down, I will answer as soon as possible.
WSL (Windows Subsystem for Linux) is a specially created software layer by Microsoft to run Linux binary executables natively on Windows 11 or 10. When you install a Linux distribution on WSL, it creates a Linux environment within Windows, with its own file system and home directory. However, how to find this directory using Graphical File Explorer of Windows? If you don’t know that then in this article, we learn about it.
The default home directory for the user account in WSL is located at /home/<username> which can be accessed using the Command line interface of WSL running bash.
For example, if your username is H2s, your home directory in WSL would be located at /home/h2s. By default, when we start the WSL Linux app, we are in our Home directory. You can switch to that using:
cd /home
The working of the home directory in WSL Linux is similar to the traditional Linux distros we are running on virtual machines, containers, or bare systems. It holds all files related user’s personal files and configuration settings. All the files of the home directory are only meant to use for your WSL instance and will not interfere with the Windows file system or vice versa…
Although we are showing this tutorial using for Ubuntu subsystem, the process will be the same for others too such as OpenSUSE, Kali, and Debian installed on WSL.
Steps to Find the WSL home directory using the GUI file explorer of Windows
- On your Windows 10 or 11, go to File Explorer or simply open MyPC to get it for finding the WSL Linux app home folder.
- After that from the left side panel scroll down to the end.
- Open WSL Linux File Explorer: There you will see the Linux Penguin icon, click that.
- Now, all the installed Linux apps such as Ubuntu, Debian, Kali, etc. on your WSL will show in the folder.
- For example, if we open the Ubuntu folder then inside that we will have a directory called ‘home‘. Open that and you will find the user of that WSL Linux app along with other files.
- After selecting the Linux WSL app, open the Home directory you want to explore manually using the GUI.
Additional tip:
To access all Windows 11 or 10 system drives under the Command Terminal of Ubuntu or another Linux environment installed on Windows WSL; we need to follow the mounting command of Linux.
Note: One thing to be mentioned is that the Bash Shell of the Linux environment should be launched under the Administrative right to access the system folders of Windows. To give administrative permission just right-click on the installed Linux environment such as Ubuntu and select “Run as Administrator”.
From your Linux Bash Shell type the following command to mount C: Drive:
cd /mnt/c ls
In the same way for D: drive type
cd /mnt/d ls
In this way, we can also mount both internal and external drives attached to our Windows 11 or 10 systems including the network drives.
Other Articles:
- Install Git LFS on WSL2 – Windows 11 or 10?
- How to install Anaconda on WSL Windows 10/11 using Ubuntu Linux App
- How to install Oracle Linux on Windows 10 or 11 WSL – Subsystem
- Install WSL- Windows Subsystem for Linux on Windows 11
- How do I access Windows folder from WSL?
- Can WSL access Windows files?
- How do I mount a Windows drive in WSL?
- How do I access Windows files from WSL 2?
- How do I copy files from WSL to Windows?
- How do I share files between Windows and WSL?
- How do I enable WSL on Windows?
- How do I open WSL files on Windows?
- How view Linux files in Windows?
- Where are WSL files stored?
- What is MNT WSL?
- How do I mount a drive in Windows 10?
How do I access Windows folder from WSL?
Access Windows Subsystem for Linux files on Windows
- Open WSL terminal.
- Navigate the root directory or top folder inside of the Terminal.
- Type in explorer.exe and hit Enter to open that location inside of the File Explorer.
Can WSL access Windows files?
WSL also allows you to run Linux command-line tools and apps alongside your Windows command-line, desktop and store apps, and to access your Windows files from within Linux. This enables you to use Windows apps and Linux command-line tools on the same set of files if you wish.
How do I mount a Windows drive in WSL?
How to Mount Windows Network Drives in WSL
- Note the letter of the network drive that you would like to map in WSL. We will use M: in this example.
- Create a new folder for that drive letter under /mnt if it does not already exist. ( ex: mkdir /mnt/m )
- Mount the drive with sudo mount -t drvfs M: /mnt/m.
How do I access Windows files from WSL 2?
1 Answer
- Open File Explorer.
- Type \\wsl$ in the address bar.
- My distro shows up and click on it and you can see the file system.
How do I copy files from WSL to Windows?
So, from WSL you can copy files back and forth from Windows/Linux by copying files into these folders. For example, my home directory in Windows is mounted in /mnt/c/Users/mbuckaway. So, I can place files there to get access from Windows. You can work from this directory in WSL and then everything will be shared.
Share folder between Windows and WSL
- Project located in the Windows file system, accessed via /mnt/ in WSL.
- Symlink (created in WSL bash) of project located in the Windows file system.
- Copy the project to the WSL file system.
How do I enable WSL on Windows?
To install WSL using Setting on Windows 10, use these steps:
- Open Settings.
- Click on Apps.
- Under the «Related settings» section, click the Programs and Features option. …
- Click the Turn Windows features on or off option from the left pane. …
- Check the Windows Subsystem for Linux option. …
- Click the OK button.
How do I open WSL files on Windows?
Ways to run WSL
From Windows Command Prompt or PowerShell, to open your default Linux distribution inside your current command line, enter: wsl.exe . From Windows Command Prompt or PowerShell, to open your default Linux distribution inside your current command line, enter: wsl [command] .
How view Linux files in Windows?
First, the easy one. From within the Windows Subsystem for Linux environment you want to browse, run the following command: explorer.exe . This will launch File Explorer showing the current Linux directory—you can browse the Linux environment’s file system from there.
Where are WSL files stored?
Note: In beta versions of WSL, your “Linux files” are any of the files and folders under %localappdata%\lxss – which is where the Linux filesystem – distro and your own files – are stored on your drive.
What is MNT WSL?
Now the /mnt/wsl path is a recursive shared tmpfs mount that does not have the distros root filesystems automatically mounted. The upside of this is it allows users much greater flexibility of what to share with other distros (for example create a recursive bind mount of you’re entire distro including submounts).
How do I mount a drive in Windows 10?
How to mount drive on Windows 10
- Open Start.
- Search for Create and format hard disks partitions and click the top result to open Disk Management.
- Right-click the drive and select the Change Drive Letter and Path option. …
- Click the Add button. …
- Select the Assign the following drive letter option.
Windows Subsystem for Linux (WSL) has become increasingly popular among developers and system enthusiasts who want to run a Linux environment alongside their Windows operating system without the overhead of a traditional virtual machine. With WSL, you can enjoy the power of Linux while still leveraging the familiarity of Windows for your daily operations. One common question that arises among WSL users is how to access Linux files from Windows. This article will guide you through the various methods to access your WSL files in both Windows 10 and Windows 11.
Understanding WSL: A Brief Overview
Before we dive into how to access WSL files in Windows, it’s essential to understand what WSL is. Windows Subsystem for Linux is a compatibility layer for running Linux binary executables natively on Windows 10 and Windows 11. WSL allows users to run a Linux distribution alongside Windows without the need for traditional virtualization methods.
WSL has two versions:
- WSL 1: The original version that translates Linux system calls into Windows calls.
- WSL 2: Introduced an actual Linux kernel that runs in a lightweight virtual machine, offering improved compatibility and performance.
Regardless of the version, accessing files stored in WSL is possible directly from your Windows file system using several methods.
Accessing WSL Files via File Explorer
One of the easiest ways to access your WSL files is through Windows File Explorer. Here’s how to do it:
-
Open File Explorer: You can open File Explorer by clicking on the folder icon in your taskbar or pressing
Windows + E
. -
Locate the WSL Files: In the address bar of File Explorer, type the following path and press Enter:
\wsl$
This command allows you to access all the installed WSL distributions and their files effortlessly. Depending on your version of Windows, you may see various installed distributions here, such as Ubuntu, Debian, or any other you have installed.
-
Navigate to Your Files: Clicking on your desired distribution (e.g.,
Ubuntu
) will open the root file system of your Linux installation. You can navigate through the familiar Linux directories, such as/home
,/etc
, and others to find your files. -
Copy or Edit Files: You can copy files from WSL to Windows or vice versa using standard drag-and-drop operations or copy-paste functionalities.
Note:
While accessing files via File Explorer is convenient, directly manipulating system files located in /proc
or /sys
is generally discouraged, as this can lead to unexpected behavior in your WSL instance.
Accessing WSL Files via Command Prompt or PowerShell
Another method to access WSL files from Windows is by using the Command Prompt or PowerShell. This approach allows you to execute commands to transfer files between Windows and your Linux installation. Here’s how:
-
Open Command Prompt or PowerShell: You can do this by typing
cmd
orPowerShell
in the Windows search bar and pressing Enter. -
Navigate to WSL Files: To access a specific file in your WSL environment, you can use the
wsl
command followed by the Linux command you want to execute. For example, to list the contents of your home directory, you can type:wsl ls ~
-
Copy Files from WSL to Windows: You can use the
wsl
command along with Windows commands to copy files. For example, to copy a file from the WSL home directory to your Windows Desktop, use:wsl cp /home/username/file.txt /mnt/c/Users/YourWindowsUsername/Desktop
Replace
username
with your WSL username andYourWindowsUsername
with your actual Windows user account name. -
Access Windows Files from WSL: You can also access your Windows files from WSL. In your WSL terminal, the Windows file system is mounted under
/mnt/c/
, so you can navigate to it easily:cd /mnt/c/Users/YourWindowsUsername/Documents
Accessing WSL Files via the Terminal Interface
For users who prefer using a terminal interface, WSL is incredibly user-friendly. You can directly interact with the files in your WSL environment through the terminal.
-
Open WSL Terminal: Open your preferred WSL terminal (e.g., Ubuntu, Debian).
-
Use Linux Commands: Familiarize yourself with basic Linux commands such as
ls
,cp
,mv
, andrm
to navigate and manipulate files within your WSL instance.- List files:
ls
- Change directories:
cd
- Copy files:
cp
- List files:
-
Intent to Access Windows Files: Use the
/mnt
directory to access the Windows file system. For instance,/mnt/c
refers to the C: drive.
Example Commands to Access and Transfer Files
-
To view the contents of a directory:
ls /mnt/c/Users/YourWindowsUsername/
-
To copy a file from WSL to the Windows desktop:
cp ~/myfile.txt /mnt/c/Users/YourWindowsUsername/Desktop/
-
To copy a file from your Windows desktop to WSL:
cp /mnt/c/Users/YourWindowsUsername/Desktop/myfile.txt ~/
Leveraging the WSL File System
While accessing WSL files from Windows is straightforward, understanding where these files reside within the WSL file system is vital for effective use.
-
The Linux root file system is located in a virtualized environment and is not directly accessible like regular Windows files. Still, WSL translates file paths so users can find files through
\wsl$
. -
Your home directory in WSL can be found at:
/home/username
Here,
username
is your Linux username.
Using Third-party Tools
Aside from the built-in tools provided by Windows, several third-party applications can enhance your experience when managing WSL files. These tools provide graphical interfaces that simplify navigation and file transfers between Windows and WSL environments.
File Managers
-
Nautilus: If you are comfortable with Linux tools, consider using a graphical file manager within a GUI-enabled Linux distribution running on WSL. Nautilus, the default file manager for GNOME, can provide an intuitive way to interact with files.
-
WinSCP: WinSCP is a popular FTP client that supports secure file transfers and has a built-in file manager. While primarily for remote servers, it can connect to WSL if you set up an SSH server within your WSL environment.
-
Other Options: Software applications such as
Total Commander
orFreeCommander
, offer dual-pane file management and can provide a visual means to access WSL files.
Syncing Files Between Windows and WSL
Keeping files synchronized between WSL and Windows can be essential for a seamless workflow. Below are methods to ensure your files remain accessible and up-to-date in both environments.
Using Git
If you work on projects that rely on code management, Git is an excellent tool that can help you keep track of changes and sync files across environments.
-
Initialize a Git Repository: Set up a Git repository in your WSL environment and clone it in your Windows file system or vice versa.
-
Push Changes: After making changes, you can commit and push from WSL and pull changes from Windows or the other way around.
-
Collaboration: Using Git also allows for better collaboration, especially if you are working on shared projects with other developers.
Cloud Storage Solutions
Another way to keep files in sync is by using cloud storage solutions like OneDrive, Google Drive, or Dropbox.
-
Install the Client: Make sure you have the client installed on your Windows OS.
-
Access the Cloud Folder: Use your WSL terminal to navigate to the cloud storage folder. For OneDrive, it will typically be located in
/mnt/c/Users/YourWindowsUsername/OneDrive
. -
Save Files to the Cloud: You can save or access files from your cloud storage directly through WSL.
Common Issues and Troubleshooting
While accessing WSL files is largely straightforward, you may encounter some common issues. Below are potential problems and their solutions:
Problem: Files Not Visible
If you cannot see the files you expect, ensure you are in the correct directory. Use the pwd
command to confirm your current directory in WSL, or check the \wsl$
path in File Explorer.
Problem: Permissions Issues
You may run into permission issues when trying to access certain directories. In Linux, permission settings dictate who can read, write, or execute files.
-
Using
chmod
: Use commandchmod
to change permissions. For example, to grant all users read and write permissions, run:chmod 777 filename
-
Check Files with
ls -l
: This command lists the files along with their permissions.
Problem: WSL is Slow
If WSL seems incredibly slow, consider the type of operations you are performing. Accessing files at the WSL file system level through /mnt/c
can be slower than accessing Linux-native files. For performance-sensitive operations, access files directly from the WSL file system instead.
Conclusion
Accessing your Linux (WSL) files in Windows 10 and Windows 11 can enhance your workflow and productivity, allowing you to leverage the strengths of both operating systems. Whether you choose to use File Explorer, command-line tools, graphical file managers, or cloud services, there are various methods to access and manage your WSL files effectively. By understanding where these files reside and how to navigate between environments, you can further harness the power of WSL in your daily tasks.
By employing these techniques and tools, you can maximize the utility of WSL and create a more integrated development environment—allowing for smooth transitions between Windows and Linux while taking full advantage of both worlds.