WSL

Both the Windows and Linux operating systems include applications that would be useful for either operating arrangement.

Unfortunately, to utilize Linux programs in Windows, you would typically need to find versions that have been ported to Windows.

Using the Windows Subsystem for Linux (WSL), yous can now launch Linux applications directly in a Windows 10 command prompt or PowerShell prompt.

How to run Linux programs in a Windows 10 control prompt

Final week we explained how you could launch Windows 10 programs within a WSL Linux distribution.

Today, we will show yous how to execute Linux applications directly in a control prompt using the wsl.exe console application.

The wsl.exe command is a Windows Subsystem for Linux utility that launches the default installed Linux distribution when executed without any arguments.

This control also has the -e command-line argument that volition launch an application from the default WSL Linux distribution directly in a Windows command prompt.

WSL help
WSL help

When launching a Linux awarding in the command prompt, the command volition interact with the Windows file system rather than the Linux distribution filesystem.

The Linux application'southward output volition also be displayed directly in the command prompt so that other Windows programs can use it.

For case, using the control discover . -name *.txt will use the default Linux distro'south detect control to search the current Windows folder and its subfolders for files catastrophe with the .txt extension.

It will then display any that are establish, equally shown beneath.

Using the Linux find command in a command prompt
Using the Linux find command in a command prompt

When executing commands, WSL will utilize the default installed Linux distribution. To check which distribution is the default ane, you can run the wsl -l command.

List default WSL distribution
Listing default WSL distribution

If you wish to run a command from a unlike Linux distribution, you would need to utilize the -d command-line statement.

For case, to run Metasploit from Kali Linux in the Windows 10 command prompt, you would use thewsl -d kali-linux -east msfconsole command.

Run Kali-Linux metasploit in Windows 10 command prompt
Run Kali-Linux Metasploit in Windows 10 command prompt

In improver to running Linux commands in a Windows 10 command prompt, you can utilize both native Windows programs and WSL Linux programs with each other.

Fifty-fifty amend, you can do so from a PowerShell prompt also.

For case, if y'all wanted to use PowerShell to listing all recently installed updates, but merely display the update proper noun and its install date, you can use the following control:

          get-hotfix | wsl -east awk -F '[[:space:]][[:infinite:]]+' '{ print $3,$v}'        

The above control uses the get-hotfix PowerShell command to listing all recently installed updates and the Linux awk command to process its output.

Using the awk command to process a Windows commands output
Using awk to process a Windows control's output

As yous tin run into, having the ability to mix and match Windows and Linux applications extends both the Windows 10 control prompt and PowerShell to execute complex and powerful commands.

The merely caveat to this interoperability is that yous cannot currently launch Linux commands that crave elevated Windows privileges.