Creating a link between local Windows files and WSL (Windows Subsystem for Linux) is a useful way to share files between the two environments.
In this guide, I’ll show how to link a folder in Windows to your WSL instance using the ln
command, and also explain how to remove a linked folder.
> Create a New Linked Folder for WSL
> Create and Modify Files in the Linked Folder
> Remove a Linked Folder
> Final Thoughts
Create a New Linked Folder for WSL
The ln
command in Linux is used to create links between files. In this example, we’ll use a symbolic link to share a folder between the Windows file system and WSL.
First, ensure that you’re familiar with the /mnt/c
path, which is where your C: drive is mounted in WSL.
To link a folder from Windows (e.g., a projects
folder on your C: drive), use the following command:
# Create sym link wsl to the projects folder ln -s /mnt/c/projects
The -s
flag creates a symbolic link (as opposed to a hard link), allowing you to access the folder in both WSL and Windows.
Create and Modify Files in the Linked Folder
Once the link is created, you can create a folder or a file within your WSL environment that is directly tied to your Windows file system.
For example, in the screenshot below I’m creating a new file within the linked folder:
This has created a folder and a file within the linked projects
folder, which is located on my Windows file system.
You can view and modify these files from either Windows or WSL.
Remove a Linked Folder
If you no longer need the link, you can easily remove it. First, list the files to check for existing links, then use the rm
command to delete the symbolic link:
# List files in the linked folder to confirm the link ls -lai ~/projects # Remove the symbolic link (only deletes the link) rm ~/projects
Note that using rm
only removes the symbolic link in the WSL environment; the original folder and files on your Windows drive remain intact:
Final Thoughts
Creating links between local Windows files and WSL is a simple and effective way to share files between the two environments. However, it’s important to note that using mounted Windows drives for version-controlled projects can lead to issues, like chmod
errors.
For smoother operation, it’s best to create rule-based links or store version-controlled projects in the Linux file system. This method provides flexibility for working across both environments while maintaining a stable workflow.
Comments
One response to “Create a Link Between Local Windows Files and WSL”
I am a Brazilian programmer. For me the above method worked perfectly on Windows 11 with Ubuntu 22.04. Thanks!