With the Windows Subsystem for Linux (WSL) you may indeed want to whistle while you work!

The WSL is faster than a standard VM and doesn’t require that you run Docker for windows to run a Linux container. It’s quite refreshing to be able to run Windows and Linux together with a minimum amount of effort. Having said that, i’m not quite ready to give up on my Raspberry Pi’s yet…

WSL is great for developers who need to build solutions which run in both environments. It’s also great when you want to run bash or Linux commands from Windows without having to install Cygwin or a similar version. The WSL is primarily a command line interface and not intended for GUI environments like KDE and Gnome. Be sure to review the FAQ’s to ensure WSL will fit your Uses Cases.

Simply follow the Microsoft WSL install guidelines and choose your Linux distribution from the Microsoft store and you’re good to go. I chose the Ubuntu 18.04.3 LTS release and am curious to try the Alpine.

# be sure to update and upgrade often
sudo apt update && sudo apt upgrade

With WSL installed you’ll be able to seamlessly interoperate between Windows and Linux shells. Just be sure when you want to run a Windows native command from Linux, to include the command extension. For example, if you want to run Notepad you would enter notepad.exe.

Note: you must add the .exe extension as notepad.exe above.

# example running windows ipconfig command from linux
root@Me-YT:~# ipconfig.exe | grep IPv4 | cut -d: -f 2

Similarly you can run Linux commands from Windows as long as you prefix the command with wsl first.

# run linux commands from windows
C:\Home\dev\Go\src\github.com\me\sandbox>wsl ls
cert.pem  file.txt  key.pem  serve.go  sha1sum.go  simple_server.go

# example running grep through wsl
C:\> wsl grep  sha1ForFile sha1sum.go
func sha1ForFile (fileName string) {

You can access the Windows filesystem through Linux, it’s mounted to the /mnt folder.

# windows filesystem mounted to /mnt
root@Me-YT:~# ls /mnt/c/Tools
Go  Install  PuTTY  apache-maven-3.6.3  bin  cygwin

If you need to pass arguments to a command you can include them in quotes.

# example using bash from windows to run a linux command
#  arguments are passed in quotes
bash -c "ls -lrt"
total 12
-rwxrwxrwx 1 root root 1094 Jan 23 11:32 cert.pem
-rwxrwxrwx 1 root root 1704 Jan 23 11:32 key.pem
-rwxrwxrwx 1 root root  205 Jan 23 11:34 serve.go
-rwxrwxrwx 1 root root   38 Jan 24 08:11 file.txt
-rwxrwxrwx 1 root root  562 Jan 24 15:30 simple_server.go
-rwxrwxrwx 1 root root  977 Jan 24 15:43 sha1sum.go

This should be enough to get you started. I hope you found this an interesting read and look forward to your comments.

Leave a comment

Your email address will not be published. Required fields are marked *