Windows Linux Subsystem - Accessing Files outside of Ubuntu

96

32

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?

Dave Hamilton

Posted 2016-06-03T09:32:28.353

Reputation: 1 081

Is it possible to mount the windows HDD under the Linux environment? In that way it should show all the files in realtime... (or even only the directory of the Cygwin home) – Hastur – 2016-06-03T10:52:29.563

3Great idea, But unfortunately the files are not visible. The way around it, is to Copy files from Windows Directory to the Linux Sub System Directory via Bash.exe Doing it this way need cp -r --no-preserve=all To drop the previous permissions. Still, if you want to make any heavy changes, you cannot use a windows application to edit the file in the LinuxSubSystem, You have to edit it, in your windows Directory and then copy it over.

Now i know this, its workable, BUT i was under the impression the Linux Sub System was more native / integrated into windows than an Isolated OS – Dave Hamilton – 2016-06-03T10:58:00.010

You can keep up with the progress of this issue (handling of files between Windows and WLS) at https://github.com/Microsoft/BashOnWindows/issues/1051

– Gaia – 2016-09-08T04:15:26.630

If you install a distro from the Windows Store, the filesystem will be at %LocalAppData%\Packages\<some-long-name-of-distro>\LocalState\rootfs. – Ian Kemp – 2018-11-08T09:36:29.887

Answers

113

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.

scottt732

Posted 2016-06-03T09:32:28.353

Reputation: 1 284

1You are correct, I think i jumped the gun a little. While Bash can access windows files, Windows cannot copy files into the Linux Sub System directory. (it can copy then, but Bash cannot see them as it preserves the files permissions) When i got bash installed, I though the most logical thing was to move my projects from one Linux Environment to another (Attempt to bin off Cwygin), And its this that started me down the route of headaches. I have configured my Bashrc now to have a starting directory of my previous Linux environment now and working from there. Thank you for your response. – Dave Hamilton – 2016-06-06T15:20:22.070

Wait, how do you get /mnt/d to show up? for instance, when I connect a phone via MTP it shows up under a path like "This PC\PhoneName" but there is no drive letter associated with it. – Michael – 2016-12-20T16:49:20.003

Symlinks work if you don't have a trailing slash. Also, you need to have files on the Windows side of the file system to do things like run Django projects locally and access them in the browser – Zags – 2017-02-15T19:24:53.697

but the linux files don't update when i modify the windows files?!?! – oldboy – 2017-08-11T22:42:23.453

22

@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.

Riz

Posted 2016-06-03T09:32:28.353

Reputation: 351

it doesn't actually sync... unless i have to restart the server every time? – oldboy – 2017-08-11T22:32:29.577

@Anthony its symbolic link, so you should not need to restart server for this. Actually this is not sync, its just pointing to that folder/path. – Riz – 2017-08-18T14:48:55.400

1

I figured out the issue. It was because the CSS file had a dash in the name like, for example, css-file.css. I have posted about this issue here.

– oldboy – 2017-08-18T22:32:00.397

9

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.

Richard Turner

Posted 2016-06-03T09:32:28.353

Reputation: 1 233

1

I had a need for working with PyCharm / eclipse on Windows 10 while for running / testind I needed a Linux environment;

I had issues for checking out from git into Linux Sub System and editing with PyCharm files were not seen immediately and had issues;

devcode=/DevCode

if [ ! -L $devcode ]; then
     ln -s /mnt/c/DevCode /DevCode 
fi

I had the above in my .bashrc in the Ubuntu area. It's working seamlessly. I could edit Windows and run / test in Ubuntu without any issues.

Narayanaa

Posted 2016-06-03T09:32:28.353

Reputation: 11

0

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.

kometen

Posted 2016-06-03T09:32:28.353

Reputation: 101