How to copy a file from Windows Subsystem for Linux to Windows drive C?
So I wrote a small program that calculates the Fibonacci sequence in the C programming language and wanted to move the fibo.c file to my regular C drive. The thing is I wrote it using Nano in Ubuntu running on the Windows Subsystem for Linux. When I try using the cp command to copy the file to /mnt/c which is where my C drive is, I get the error: "cp: cannot create regular file 'mnt/c/fibo.c': Permission denied". Anyone know how to circumvent this?
Note: I also tried using 'sudo cp' as well.
34 Answers
Does seem like an older issue, but might prove useful for others: I find the easiest way to achieve file copies from WSL to windows without having to struggle with permissions is as follows:
1) Open "File explorer"
2) Connect to your running WSL instance just like you would connect to a network drive:
--> Enter \\wsl$\< WSL_Distro > in the address bar
3) Browse your WSL folder structure ;)
From here you can copy your Linux files, and paste them on your windows folders. Do note that I do not recommend that you copy file from windows to WSL using this method.
If you want to copy to WSL, Best use the "/mnt/" method!
3Maybe this will work for you:
- Copy the file you want to share
- Open ubuntu bash
- Type
explorer.exe .in ubuntu bash - Paste the files
The Widnows is mounted at this location
/mnt/c/Users/[Username]/..Just copy the files to this location.
1You do not have permissions to move the file:
Check the permissions by doing:
ls -lIf the above says root this means that the superuser sudo has the access.
You can elevate your permissions by prefixing sudo before your command
sudo cp ~/fibo.c /mnt/c/fibo.c'