The Windows file system and the WSL file systems are different!

Although there are certain differences between the Windows and WSL file systems, they are merged to facilitate compatibility. Here's a thorough breakdown of their distinctions and how to switch between them:

Differences Between Windows and WSL File Systems:

  1. File System Type:

    • Windows uses the NTFS file system, while WSL uses a Linux file system, typically ext4.
  2. File Path Format:

    • Windows file paths use backslashes \ (e.g., C:\Users\JP\Documents) and drive letters.

    • WSL file paths use forward slashes / (e.g., /home/jp/documents) and do not use drive letters.

  3. Case Sensitivity:

    • NTFS is case-insensitive: file.txt and FILE.TXT are considered the same.

    • Linux file systems are case-sensitive: file.txt and FILE.TXT are different files.

  4. Permissions:

    • Windows and Linux have different file permission models. WSL translates Windows permissions to their closest Linux equivalents, but there are differences in how permissions are handled and applied.

Accessing Windows Files from WSL:

From within WSL, Windows drives are mounted under the /mnt/ directory. For example, the C: drive is mounted as /mnt/c/.

To browse Windows files from WSL, you can use the cd command to change directories. For example:

cd /mnt/c/Users/JP/Documents

You can then use Linux commands such as ls to list files, cp to copy files, and so on.

Accessing WSL Files from Windows:

In Windows 10 version 1903 and later, you can access the WSL file system directly from File Explorer.

  1. Using File Explorer:

    • Open File Explorer.

    • Type \\wsl$ in the address bar to see a list of running WSL distributions.

    • Navigate to the distribution you want to access, and then to the Linux file system.

  2. Using Command Line:

    • In a Command Prompt or PowerShell window, you can also navigate to \\wsl$ followed by the distribution name and the path to the file.

For example:

cd \\wsl$\Ubuntu-20.04\home\jp\projects

Important Notes:

  • Performance: It takes longer to access Windows files using WSL than it does to access them straight from Windows. In a similar vein, WSL files open more slowly in Windows than they do in WSL.

  • Editing Files: Generally speaking, using VSCode or any WSL-compatible editor to edit WSL files from Windows is safe. On the other hand, file permissions and metadata problems may arise when Windows programs are used to modify Linux files stored in the WSL file system.

  • Storing Files: Keeping project files on the same file system as the tools you'll be using is advised. Use the WSL file system to store your files if you're using Linux tools.

You can use both the Windows and WSL environments to create and manage files by being aware of these distinctions and knowing how to move between the file systems.