130

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?

4
  • 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 Jun 3 '16 at 10:52
  • 3
    Great 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 Jun 3 '16 at 10:58
  • You can keep up with the progress of this issue (handling of files between Windows and WLS) at github.com/Microsoft/BashOnWindows/issues/1051 – Gaia Sep 8 '16 at 4:15
  • 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 Nov 8 '18 at 9:36
164

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.

5
  • 1
    You 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 Jun 6 '16 at 15:20
  • 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 Dec 20 '16 at 16:49
  • 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 Feb 15 '17 at 19:24
  • but the linux files don't update when i modify the windows files?!?! – oldboy Aug 11 '17 at 22:42
  • Note that a) slash must be forward slash and b) drive letter is case sensitive. – Ivan Chau Oct 22 '20 at 4:00
30

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

3
  • it doesn't actually sync... unless i have to restart the server every time? – oldboy Aug 11 '17 at 22:32
  • @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 Aug 18 '17 at 14:48
  • 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 Aug 18 '17 at 22:32
13

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.

3

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.

2

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.

1
  • I'd advice against directly putting symlinks in the root, and I don't see why the link needs to be reestablished every time, the symlink should persist (at least when placed in a sensible location). – Maarten Bodewes Feb 17 at 11:54
1

A simple GUI way to open folder path of Windows inside your Linux shell (WSL) is: (I have a Windows 10 enterprise with Ubuntu WSL)

  1. Go to windows folder (which you want to access from Ubuntu/Linux)
  2. Shift + Right Click -> If you have installed and configured WSL on Windows correctly, you should see the Open Linux Shell Here option (as shown in image)

enter image description here

1
  • 1
    I presume this is something newly added as i have not heard or seen this before. But this is actually really good. Due to job i have to use Windows Native, but Unix / Linux tools are too powerful to not use daily, Working with such a large folder structure this will save me ALOT of time. Thanks – Dave Hamilton Jun 23 at 17:54
1
%LocalAppData%\Packages\<some-long-name-of-distro>\LocalState\rootfs 

worked for me.

1

\\WSL$

(Dummy text: Body must be at least 30 characters; you entered 5.)

Edit: aha a slash was being stripped. Has been fixed. Two backslashes.

4
  • nope (11 more to go...) – Martin Zaske Jul 7 at 13:16
  • Now I get it, when I use my normal Windows File Explorer, it should be \\WSL$ with a double back-slash, like in some network address. This is truely an elegant way to access files which I have generated or modified with my WSL Linux tools. Thank you. – Martin Zaske Jul 7 at 13:19
  • This answer is the opposite of what was asked but today very useful to me. Seems that MS is discouraging users to access files inside the WSL from outside (or in other words from the main Windows installation). But this is not a hack, it seems to behave like a proper network share and I could just copy over an entire folder-structure with some 3000 small files (a font in .ufo format) without any problems. This would deserve its own question and would be The answer. – Martin Zaske Jul 7 at 13:31
  • Somewhere in the discussion someone started tslking about moving files to Linux so I might have gotten sidetracked? Did they not want to copy to the subsys? If they are trying to access windows files then I think mnt or use the right click. Yeah WSL$ is not a hack. – Jon Jul 8 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.