Cool Life Hacks for Working with WSL (Windows Subsystem for Linux)

I am deeply immersed in WSL (Windows Subsystem for Linux), and now that WSL2 is available in Windows Insiders , this is a great time to really explore the options available. A very interesting feature that I found in WSL is the ability to "cleanly" move data between worlds. This is not an experience that you can easily get with full-fledged virtual machines, and it talks about the tight integration of Linux and Windows.



Under the cut, more on some of the interesting things you can do by mixing peanut butter and chocolate!







Launch Windows Explorer from Linux and access your distribution files



When you are on the WSL / bash command line and want to get visual access to your files, you can run “explorer.exe.”, Where the current directory is located, and you will get a Windows Explorer window in which your Linux files will be delivered to you through the server LAN plan9.







Use true Linux commands (not CGYWIN) from Windows



I already wrote about this before, but now there are aliases for PowerShell functions that allow you to use real Linux commands from within Windows.



You can call any Linux command directly from DOS / Windows / anything by simply placing it after WSL.exe, like this.



C:\temp> wsl ls -la | findstr "foo" -rwxrwxrwx 1 root root 14 Sep 27 14:26 foo.bat C:\temp> dir | wsl grep foo 09/27/2016 02:26 PM 14 foo.bat C:\temp> wsl ls -la > out.txt C:\temp> wsl ls -la /proc/cpuinfo -r--r--r-- 1 root root 0 Sep 28 11:28 /proc/cpuinfo C:\temp> wsl ls -la "/mnt/c/Program Files" ...contents of C:\Program Files...
      
      





Windows executables can be called / run from WSL / Linux, since the path to Windows is in $ PATH to Windows. All you have to do is explicitly call it with .exe at the end. This is how Explorer.exe works. You can also make notepad.exe or any other file.



Launch Visual Studio Code and get access to your Linux applications natively on Windows



You can run “code.” While in a folder in WSL, and you will be prompted to install the VS Remote extensions. . This effectively divides Visual Studio Code in half and runs the “headless” VS Code Server on Linux with the VS Code client in the Windows world.



You also need to install Visual Studio Code and the Remote extension - WSL . If desired, install the beta version of Windows Terminal for a better terminal experience on Windows.



Here's a great selection of articles from the Windows Command Line blog.





Here are the benefits of WSL 2





Launch multiple Linux in seconds



Here I use "wsl --list --all", and there are already three Linux on my system.



 C:\Users\scott>wsl --list --all Windows Subsystem for Linux Distributions: Ubuntu-18.04 (Default) Ubuntu-16.04 Pengwin
      
      





I can easily launch them, and also assign profiles so that they appear in my Windows Terminal.



Launch X Windows Server under Windows with Pengwin



Pengwin is a special WSL Linux distribution that is very cool. You can get it in the Windows Store . Combine Pengwin with an X Server, such as the X410 , and you get a very cool integrated system.



Easily move WSL distributions between Windows systems.



Ana Betts notes this wonderful technique with which you can easily transfer your ideal WSL2 distribution from one machine to n machines.



 wsl --export MyDistro ./distro.tar #   -, Dropbox, Onedrive, -  mkdir ~/AppData/Local/MyDistro wsl --import MyDistro ~/AppData/Local/MyDistro ./distro.tar --version 2
      
      





That's all. Get the perfect Linux setup synced across all your systems.



Use Windows Git Credential Provider Inside WSL



All of the features listed culminate in this cool post from Ana Betts , where she integrates the Windows Git Credential Provider into the WSL , turning / usr / bin / git-credential-manager into a shell script that invokes the git creds manager of Windows. Ingenious. This would be possible only with clean and tight integration.



Try it, install WSL, Windows Terminal , and create a brilliant Linux environment on Windows. .



All Articles