Create a Link Between Local Windows Files and WSL
Create a Link Between Local Windows Files and WSL
The ln command in Linux is used to create a link between files. This is useful for sharing files between your local machine and WSL.
I’m linking to a ‘projects’ folder in this post but I get an error when cloning git repos in them (chmod error). Using mounted Windows drives for version-controlled projects is appearing to be a no-go.
# Create a New Linked Folder
# Remove a Linked Folder
Create a New Linked Folder
# Create sym link wsl ln -s /mnt/c/projects
-s
Create symbolic links instead of hard links.
First I’m creating a local folder and then creating a link to the folder in my WSL home directory.
![PowerShell New-Item](https://peter-whyte.com/wp-content/uploads/2020/09/new_project_link_with_wsl_b.png)
Next, I’m creating a new folder and file within WSL on the linked folder.
![Create Folder and File Linux](https://peter-whyte.com/wp-content/uploads/2020/09/wsl_create_python_dir_in_linked_folder_b.png)
And here’s the file created above shown within the local Windows environment.
![Folder and File in Windows Explorer](https://peter-whyte.com/wp-content/uploads/2020/09/wls_linked_folder_windows_folder_view.png)
Remove a Linked Folder
List the files (-lai) to check for existing links ad then remove as your would a file (rm
command).
![Remove Symlink](https://peter-whyte.com/wp-content/uploads/2020/09/wsl_remove_linked_folder.png)
We’re deleting the object visible to Linux here, not the folder in Windows.
![](https://peter-whyte.com/wp-content/uploads/2020/09/wls_linked_folder_windows_folder_view-1.png)
3 Comments
[…] creating a new SSH key within a linked folder, which means my SSH keys are backed up on the local machine in-case anything happens on this WSL […]
[…] encountered this error message when attempting to clone a git repo on a linked folder within […]
I am a Brazilian programmer. For me the above method worked perfectly on Windows 11 with Ubuntu 22.04. Thanks!