Transferring Files Between Windows and WSL

windows wsl
< 1 mn read

If you’re using Windows Subsystem for Linux (WSL) and need to copy or move files between your Windows drive and your WSL instance, there are a couple of ways to accomplish this.

Method 1: Accessing Windows Files from WSL

You can access your Windows files from within your WSL instance by using the /mnt/c/path/to/file syntax. For example, if you want to move a project directory from your Windows Documents folder to your WSL home directory, you can use the following commands:

cd $HOME
mv /mnt/c/Users/youruser/Documents/project/myproject .

This command navigates to your WSL home directory ($HOME) and moves the myproject directory from the Windows Documents folder to the current directory (.).

Method 2: Accessing WSL Files from Windows

Another way to transfer files is by accessing your WSL instance’s drive from Windows. Here’s how you can do it:

  1. Navigate to \\wsl$\Ubuntu-20.04\home\your_username in Windows Explorer. Replace Ubuntu-20.04 with the name of your WSL distribution and your_username with your actual username.
  2. Simply drag and drop the files you want to transfer into this directory.

Note: WSL prohibits access to any root-owned files or directories through the \\wsl$\<distro> share.

If you need to transfer files to a directory owned by the root user in WSL, you can follow these steps:

  1. Create a new directory under the root / directory in your WSL instance:

2. Change the ownership of the newly created directory to your user:

sudo chown $USER:$USER /project

Now you should be able to access and drop files into the /project directory from Windows using the \\wsl$\<distro> share.

By using these methods, you can easily transfer files between your Windows drive and your WSL instance, making it convenient to work with files across both environments.

Leave a Reply

Your email address will not be published. Required fields are marked *

Reading is essential for those who seek to rise above the ordinary.

ABOUT US

The internet as we know is powerful. Its underlying technologies are transformative, but also, there’s a plethora of haphazard information out there.We are here to serve you as a reliable and credible source to gain consistent information

© 2024, cloudiafrica
Cloudi Africa