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:
- Navigate to
\\wsl$\Ubuntu-20.04\home\your_username
in Windows Explorer. ReplaceUbuntu-20.04
with the name of your WSL distribution andyour_username
with your actual username. - 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:
- Create a new directory under the root
/
directory in your WSL instance:
sudo mkdir /project
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.