Working beyond Windows and Linux file systems

There are a number of considerations to keep in mind when working between Windows and Linux file systems. Nosotros have outlined a few of them for y'all in this guide, including some examples of interoperability support for mixing Windows and Linux-based commands.

File storage and performance across file systems

Nosotros recommend against working across operating systems with your files, unless you take a specific reason for doing and then. For the fastest functioning speed, store your files in the WSL file organisation if you are working in a Linux command line (Ubuntu, OpenSUSE, etc). If you're working in a Windows command line (PowerShell, Control Prompt), shop your files in the Windows file system.

For example, when storing your WSL projection files:

  • Use the Linux file organization root directory: \\wsl$\Ubuntu\home\<user name>\Projection
  • Not the Windows file system root directory: /mnt/c/Users/<user name>/Project$ or C:\Users\<user name>\Project

When y'all come across /mnt/ in the file path of a WSL command line, it means that you lot are working from a mounted bulldoze. So the Windows file organisation C:/ bulldoze (C:\Users\<user proper name>\Projection) will look like this when mounted in a WSL control line: /mnt/c/Users/<user name>/Projection$. It is possible to store your project files on a mounted drive, but your operation speed will improve if you store them directly on the \\wsl$ drive.

View your electric current directory in Windows File Explorer

Yous can view the directory where your files are stored by opening the Windows File Explorer from the command line, using:

              explorer.exe .                          

Alternatively, you can also utilize the command: powershell.exe /c start . Exist certain to add the period at the terminate of the command to open the current directory.

To view all of your bachelor Linux distributions and their root file systems in Windows File explorer, in the address bar enter: \\wsl$

View project files in Windows File Explorer

Filename and directory instance sensitivity

Case sensitivity determines whether upper-case letter (FOO.txt) and lowercase (foo.txt) letters are handled as singled-out (example-sensitive) or equivalent (case-insensitive) in a file name or directory. Windows and Linux file systems handle example sensitivity in different ways - Windows is instance-insensitive and Linux is case-sensitive. Acquire more near how to adjust case sensitivity, particularly when mounting disks with WSL, in the Adjust case sensitivity how-to article.

Interoperability between Windows and Linux commands

Windows and Linux tools and commands can be used interchangeably with WSL.

  • Run Windows tools (ie. notepad.exe) from a Linux command line (ie. Ubuntu).
  • Run Linux tools (ie. grep) from a Windows command line (ie. PowerShell).
  • Share environs variables between Linux and Windows. (Build 17063+)

Run Linux binaries from the Windows Command Prompt (CMD) or PowerShell using wsl <command> (or wsl.exe <command>).

For example:

              C:\temp> wsl ls -la <- contents of C:\temp ->                          

Binaries invoked in this way:

  • Use the same working directory as the current CMD or PowerShell prompt.
  • Run equally the WSL default user.
  • Have the same Windows administrative rights as the calling process and concluding.

The Linux command post-obit wsl (or wsl.exe) is handled like any control run in WSL. Things such as sudo, piping, and file redirection work.

Example using sudo to update your default Linux distribution:

              C:\temp> wsl sudo apt-get update                          

Your default Linux distribution user name will be listed after running this command and you volition be asked for your countersign. After entering your countersign correctly, your distribution volition download updates.

Mixing Linux and Windows commands

Hither are a few examples of mixing Linux and Windows commands using PowerShell.

To use the Linux control ls -la to list files and the PowerShell control findstr to filter the results for words containing "git", combine the commands:

              wsl ls -la | findstr "git"                          

To use the PowerShell command dir to list files and the Linux command grep to filter the results for words containing "git", combine the commands:

              C:\temp> dir | wsl grep git                          

To use the Linux command ls -la to list files and the PowerShell command > out.txt to print that listing to a text file named "out.txt", combine the commands:

              C:\temp> wsl ls -la > out.txt                          

The commands passed into wsl.exe are forwarded to the WSL procedure without modification. File paths must be specified in the WSL format.

To utilize the Linux command ls -la to list files in the /proc/cpuinfo Linux file arrangement path, using PowerShell:

              C:\temp> wsl ls -la /proc/cpuinfo                          

To use the Linux control ls -la to listing files in the C:\Program Files Windows file arrangement path, using PowerShell:

              C:\temp> wsl ls -la "/mnt/c/Programme Files"                          

WSL can run Windows tools directly from the WSL command line using [tool-name].exe. For example, notepad.exe.

Applications run this manner have the following properties:

  • Retain the working directory equally the WSL command prompt (for the most function -- exceptions are explained below).
  • Have the same permission rights as the WSL process.
  • Run every bit the agile Windows user.
  • Appear in the Windows Task Manager as if direct executed from the CMD prompt.

Windows executables run in WSL are handled similarly to native Linux executables -- pipe, redirects, and fifty-fifty backgrounding work as expected.

To run the Windows tool ipconfig.exe, apply the Linux tool grep to filter the "IPv4" results, and use the Linux tool cutting to remove the column fields, from a Linux distribution (for instance, Ubuntu) enter:

              ipconfig.exe | grep IPv4 | cutting -d: -f2                          

Let's try an case mixing Windows and Linux commands. Open your Linux distribution (ie. Ubuntu) and create a text file: affect foo.txt. At present use the Linux command ls -la to list the direct files and their cosmos details, plus the Windows PowerShell tool findstr.exe to filter the results then only your foo.txt file shows in the results:

              ls -la | findstr.exe foo.txt                          

Windows tools must include the file extension, friction match the file instance, and be executable. Non-executables including batch scripts. CMD native commands like dir tin be run with cmd.exe /C control.

For example, list the contents of your Windows files organisation C:\ directory, by entering:

              cmd.exe /C dir                          

Or use the ping command to send an echo request to the microsoft.com website:

              ping.exe www.microsoft.com                          

Parameters are passed to the Windows binary unmodified. Every bit an example, the following command volition open C:\temp\foo.txt in notepad.exe:

              notepad.exe "C:\temp\foo.txt"                          

This will also piece of work:

              notepad.exe C:\\temp\\foo.txt                          

WSL and Windows share a special environment variable, WSLENV, created to bridge Windows and Linux distributions running on WSL.

Properties of WSLENV variable:

  • It is shared; information technology exists in both Windows and WSL environments.
  • It is a list of environment variables to share between Windows and WSL.
  • Information technology tin can format environment variables to piece of work well in Windows and WSL.
  • Information technology tin can assist in the flow between WSL and Win32.

Note

Prior to 17063, just Windows environment variable that WSL could access was PATH (then you could launch Win32 executables from under WSL). Starting in 17063, WSLENV begins being supported. WSLENV is case sensitive.

WSLENV flags

There are 4 flags available in WSLENV to influence how the surround variable is translated.

WSLENV flags:

  • /p - translates the path betwixt WSL/Linux style paths and Win32 paths.
  • /l - indicates the surroundings variable is a list of paths.
  • /u - indicates that this environs variable should but be included when running WSL from Win32.
  • /w - indicates that this environs variable should only exist included when running Win32 from WSL.

Flags can be combined every bit needed.

Read more than virtually WSLENV, including FAQs and examples of setting the value of WSLENV to a chain of other pre-divers surroundings vars, each suffixed with a slash followed by flags to specify how the value should be translated and passing variables with a script. This commodity as well includes an example for setting up a dev surround with the Go programming linguistic communication, configured to share a GOPATH between WSL and Win32.

Disable interoperability

Users may disable the power to run Windows tools for a single WSL session by running the following control as root:

              repeat 0 > /proc/sys/fs/binfmt_misc/WSLInterop                          

To re-enable Windows binaries, get out all WSL sessions and re-run bash.exe or run the following control as root:

              echo 1 > /proc/sys/fs/binfmt_misc/WSLInterop                          

Disabling interop will not persist between WSL sessions -- interop will be enabled again when a new session is launched.