2

I am running Ubuntu from Windows.

When I create a folder from Windows called newFolder in the root directory C:\Users\myuser\AppData\Local\lxss\root\Newfolder then from Bash when I run ls I don't see the new folder that was just created.

How can I fix this so that I can create folders and files from Windows then access them from Bash?

3

Update:

Since Windows 10 version 1903 it's possible to access Linux files from Windows with \\wsl$\. So you can run explorer.exe . from bash or enter \\wsl$\ directly in Explorer's address bar

See What’s new for WSL in Windows 10 version 1903?

Again there's still the warning that you must NOT access your Linux files via the AppData folder!

For older versions of Windows 10 see below


Linux files in WSL root file system are created specially with POSIX permissions stored in NTFS extended attributes. You can see that by running fsutil file layout lxss\root and notice the $EA stream there. If you create the files directly from Windows you'll mess up things because win32 apps knows nothing about Linux and its file metadata

The problem arises when, for example, you use a Windows app/tool to open, create and/or modify a file under your distro root: Since the file was created with a Windows tool, the file won't have any Linux file metadata (e.g. permissions, owner, access/update timestamps, etc.). Thus, to Linux, (which only receives Linux file metadata), the file may be reported as empty, may not even exist, or may have some metadata, but that metadata may not reflect the file's details resulted in the file's contents being corrupted.

Therefore MS has boldly warned that

DO NOT, under ANY circumstances, create and/or modify Linux files using Windows apps, tools, scripts, consoles, etc.

Creating/changing Linux files from Windows will likely result in data corruption and/or damage your Linux environment requiring you to uninstall & reinstall your distro!

Do not change Linux files using Windows apps and tools

Files that are only relevant to Linux should be created only from WSL. If you want to create files that are accessible both systems then create them outside the WSL root and access from WSL via the mount point in /mnt like /mnt/drive/path

If you want to create files on Windows file systems but retain the case sensibility then use

fsutil file setCaseSensitiveInfo <directory name> enable

The flag can also be checked with fsutil file queryCaseSensitiveInfo <directory name>

See also How to access linux/Ubuntu files from Windows 10 WSL?

  • Isn't the issue with accessing files from WSL in Windows EOL conversion? If so, that can be avoided with a cross-platform text editor like Atom or VScode, or a Windows coding editor like NotePad++ – JW0914 Aug 6 '18 at 3:45
  • @JW0914 no. who talk about text files? Did you even read what I quoted? The issue is that any files created from Windows don't have Linux metadata and may be reported as empty (which is what the OP observed), may not even exist, or may have some metadata, but that metadata may not reflect the file's details resulted in the file's contents being corrupted. Regarding EOL then even Notepad nowadays have the ability to open it whereas Wordpad and IE can open them for decades – phuclv Aug 6 '18 at 3:53
  • I overlooked your first quote block due to your second, thanks for pointing that out =] As to " Regarding EOL then even Notepad nowadays have the ability to open it whereas Wordpad and IE can open them for decades", opening yes, editing on Windows, while maintaining LF EOLs, no (although I think Notepad may finally have received that feature with it's most recent update). – JW0914 Aug 6 '18 at 4:10
  • 1
    @JW0914 Notepad does have ability to edit LF (and CR)-ending files, and it does get a ton of new features. Indeed not many people use it and it doesn't have many useful features, but see Maintaining Notepad is not a full-time job, but it’s not an empty job either – phuclv Aug 6 '18 at 4:14
3

You can not create folders in Ubuntu and access them from Windows. But you can do opposite.

You can access your Windows' drives at /mnt. If you do ls /mnt you will see all your drives. So /mnt/c is path of your C drive. Similarly /mnt/c/Users/username/Desktop can give you access to your desktop in Bash.

So just reach to your desired path using Bash and access windows files & folders. For more details on making quick access to your windows files, use symlinks, details can be found here

1

Invert your thinking: If you want to create files using Windows apps & tools, and access them from Bash, then create those files etc. in your Windows filesystem and access/copy them from Bash.

Here's an example of creating a file in PowerShell, then calling Bash to copy the created file into the home folder, and then calling bash to write the contents of the file:

PS C:\dev\temp> Set-Content ./hello.txt -Value "Hello, World!" -Encoding ASCII
PS C:\dev\temp> cat .\hello.txt
Hello, World!
PS C:\dev\temp> bash -c "cp /mnt/c/dev/temp/hello.txt ~/"
PS C:\dev\temp> bash -c "cat /mnt/c/dev/temp/hello.txt"
Hello, World!

HTH.

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.