How to Mix And Match Windows and Linux With WSL

Abstract

  • You may entry Linux and Home windows information via Home windows Explorer and WSL Linux shell home windows.
  • You may run Home windows instructions from Linux by merely appending “.exe” to them.
  • You may run Linux instructions from Home windows PowerShell utilizing the “wsl” command.


Home windows Subsystem for Linux, or WSL, is a approach to run Linux distributions in Home windows with out dual-booting or putting in digital machines, however its actual energy comes from the power to launch Home windows and Linux apps concurrently.



Accessing Linux Recordsdata from Home windows Explorer

Ubuntu WSL root directory in Windows Explorer.

You may access files for any Linux distros installed with WSL in the Windows Explorer. Look on the left-hand sidebar and you may see an icon of Tux, the Linux mascot, after which click on the triangle to broaden it to see all of the WSL distros you have put in. You may then be capable to navigate the Linux filesystem via Explorer.


You may also enter “wsl$” in Explorer to see your distros. You may also navigate on to your distro by appending a (backslash) and the identify of the distro. For instance, Ubuntu could be “$wslubuntu”. You may also specify pathnames this fashion. Simply keep in mind to vary the ahead slashes (/) to backslashes since this is how Windows separates paths.

If you’re working within the WSL command line, you possibly can open up Explorer within the present working listing with this command:

explorer.exe . 

(You may also do that from PowerShell, however this reveals how nicely WSL and PowerShell interoperate).

Accessing Home windows Recordsdata from Linux

Running ls command on /mnt/c in WSL.

You may also entry Home windows information from the Linux aspect of your machine. The letter drives on Home windows will present up as /mnt/[drive letter] within the Linux file system.


For instance, the “C:” drive will likely be mounted at “/mnt/c”. The C:Home windows listing could be “/mnt/c/Home windows”.

This will even apply to any graphical Linux apps you have got put in.

Operating Home windows Instructions from Linux

Running Notepad from WSL

To run Home windows instructions from Linux, you possibly can simply kind them from the Linux terminal and append “.exe” to them. You already noticed an instance with Explorer earlier.

You may also run different instructions. In the event you needed to open a file in Notepad, you possibly can kind this command:

notepad.exe file 

You may also run Home windows instructions in Linux pipelines, processing the output of Home windows instructions. You may search Home windows output with the Linux grep command.

Suppose we needed to search out point out of Home windows in a listing itemizing from PowerShell:



powershell.exe dir "C:/" | grep 'Home windows'

In the event you’re mixing Home windows and Linux instructions, keep in mind that whereas Home windows instructions are case-insensitive, Linux instructions are case-sensitive. Which means that Linux instructions depend upon having the proper mixture of upper-case and lower-case letters to run appropriately.

If you run Home windows instructions from Linux, they are going to have the identical Home windows permissions because the WSL course of and the energetic person. In the event you run ls /mnt/c, you will discover that the permission to record information like pagefile.sys, the Home windows pagefile, is denied, as that is normally reserved for administrative customers. In the event you use sudo, you can record all information, because the WSL will now have full permissions:

sudo ls /mnt/c 

Operating Linux Instructions from PowerShell

Running WSL Ubuntu Linux ls command from Windows PowerShell.

You may also go the opposite means by working Linux instructions from Home windows PowerShell. You are able to do this utilizing the wsl command adopted by any Linux instructions you need to run.

To record the “/bin” listing in Linux:



wsl ls /bin

Going from Home windows to Linux, the processes can have the identical permissions because the session that began the Linux command. For instance, a command issued by an everyday person can have the identical permissions, whereas a command issued with sudo will likely be escalated to superuser.

Operating Linux GUI Packages in Home windows

GNU Emacs launched from WSL

With WSL on Home windows 11, you possibly can run Linux GUI applications from Home windows. There are two methods to do that: from the command line or from the Begin menu.

To launch a GUI program from the shell, you possibly can simply invoke it from the command line. To run GNU Emacs:


emacs

One downside you could seen once you run a command this fashion is that it will probably tie up your terminal. You will not get your immediate again except you both shut this system or put within the background. To launch a program as a background course of, append an & (ampersand) to it:



emacs &

To put an already running program in the background, use the shell’s job management features. Press Ctrl+z to droop this system. That is lowercase, since keyboard combos are case-sensitive like Linux instructions are. The system will print a message with the job quantity and a message that the method is suspended. Then kind this command to place it within the background:


bg
Ubuntu WSL GUI in Windows 11 Start menu.

You may also entry GUI applications from the Begin menu. Any Linux distros will present up as a folder within the Begin menu you probably have any GUI applications put in. For instance, Ubuntu will likely be “Ubuntu.” To start out a program, you possibly can click on on it to launch it as you’d with an everyday Home windows program.

Sensi Tech Hub
Logo