Windows Linux Subsystem - Accessing Files outside of Ubuntu

Why, when I create a file from within Windows for example, can I not see it under the Linux sub system in Windows 10 (bash.exe)

The screenshot should explain.

Folder: OMG was created from within Windows Explorer. Folder OMGBash was created from with Linux sub system bash.exe

When a folder OR file is created outside of bash.exe I can never see it, regardless of permissions and ownership.

To show the information I have had to use Cygwin to show file permissions, I have also altered the permissions to see if the folder would appear. (The two command windows at the bottom)

Screenshot showing folder, bash.exe and Cygwin permissions:

enter image description here

I am trying to move all my Cygwin scripts over to the Linux subsystem, but I don't fancy recreating every file, then having to copy and past using bash, then reformatting then using Dos2unix (very long winded).

Found this on GitHub for the Linux subsystem:

copying directly into the Linux subsystem from Windows is not supported, according to discussion on other tickets. There is a directory under AppData somewhere (I forget where) that appears to contain the files for the WSL filesystem. But if you put new files there, or modify existing files there, your changes are not reflected correctly inside WSL.

My best guess is that Linux needs to store different metadata (and more caching information, etc, since its disk-buffering model is also different) about its files than Windows does, and that this is currently implemented by storing the master copy of the structure of the Linux filesystem in a database of some sort, and just using the Windows filesystem as a convenient BLOB-store for that database.

If you really need to do this, a workaround would be to write a drag'n'drop .bat script or somesuch that does bash.exe -c "mv %1 /home/$USER/". (You'll have to do some clever work with sed and tr, probably, to translate %1 to a valid WSL path.)

Alternatively -- could you put your files in a Windows directory and, within WSL, do "cd ~; ln -s /mnt/c/path/to/my/files" to make them appear to be in your WSL homedir?


Solution 1:

I'm not sure if I'm misunderstanding your question, but your ubuntu bash (top right window) should have access to your Windows-based disks under /mnt. For example, on my machine /mnt/c/Users/Scott/Desktop is my Windows desktop and I can read/write files there from vi for ex. I don't believe the opposite is true just yet. That is, I don't think you can explore into your bash world from Windows explorer.

What I've been doing as a developer is to host projects on my d: and point the linux-based tools to that /mnt/d/projects/someproject/ folder.

Make sure you update your Windows builds periodically as they seem to be fixing a lot of issues with each build, especially around sym-links and crossing FS boundaries between Linux/Windows.

Solution 2:

@scottt732 answered beautifully.

Just a tip for developers who would work in Windows and would like to access those files in Linux Subsystem real quick. You can use symbolic links.

For example If you are working on a project in d:/projects/web-project, you can create a symlink at location /var/www/web-project and all the files you change in windows will be readily available to be accessed in Linux Bash.

For this you will do use ln command like this

ln -s  /mnt/d/projects/web-project  /var/www/web-project

In above line /mnt/d was meant to be your d drive on windows. Setup your Apache virtual host to this path and you are ready to go.

Solution 3:

We recommend that you do not copy/create/update Linux files using Windows apps.

Instead, store files in the Windows filesystem (e.g. c:\dev\project) that you want to edit files using Windows tools and/or build/test/run using Linux tools/runtimes/platforms (e.g. via /mnt/c/dev/project).

In your specific scenario, if you want to copy your Cygwin files into Bash, then open Bash and copy the files from your Cygwin folder on C: into ~/, like this: cp /mnt/c/Users/dave/Documents/Cygwin/* ~/)

HTH.

Solution 4:

I had a similar need to copy files between WSL and win10. I ended up enabling sshd on the Ubuntu-installation so I could ssh into Linux from win10. Then I use winscp to copy files back and forth. Not optimal, but I don't copy files very frequently. I tried to find the post I used to enable sshd but can't locate it.