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Ā it is available inĀ Windows Insiders, it's a great time to truly explore the available options. A very interesting feature I found in WSL is the ability to 'seamlessly' move data between worlds. This is not an experience you can easily achieve with full virtual machines, and it speaks to the tight integration of Linux and Windows.

Below are some interesting things you can do by mixing peanut butter and chocolate!

Cool life hacks for working with WSL (Windows Subsystem for Linux)

Run Windows Explorer from Linux and access your distribution files

When you are in the WSL / bash command line and want visual access to your files, you can run 'explorer.exe .' from your current directory, and you'll get a Windows Explorer window where your Linux files will be delivered to you through the plan9 local network server.

Cool life hacks for working with WSL (Windows Subsystem for Linux)

Use real Linux commands (not Cygwin) from Windows

I've written about this before, but now there are aliases for PowerShell functions, which allow you to use real Linux commandsĀ from inside Windows.

You can call any Linux command directly from DOS/Windows/whatever by putting 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/runned from WSL/Linux, as the Windows path is in the $PATH before Windows. All you need to do is explicitly call them with .exe at the end. Here's how 'Explorer.exe' works. You can also do notepad.exe or any other file.

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

You can run 'code.' while in a folder in WSL, and you will be prompted to installĀ VS Remote extensions.. This effectively splits Visual Studio Code in half and runs a 'headless' VS Code Server in Linux with the VS Code client in the Windows world.

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

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

Here are the benefits of WSL 2

  • Virtual machines are resource-intensive and create a very isolated experience.
  • The original WSL was quite 'connected' but had significantly lower performance compared to VMs.
  • WSL 2 offers a hybrid approach with lightweight VMs, a fully connected interface, and high performance.

Run multiple Linux instances in seconds

Here I use 'wsl --list --all', and I already have three Linux distributions on my system.

C:Usersscott> 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 they appear in my Windows Terminal.

Run X Windows Server on Windows with Pengwin

PengwinĀ is a special Linux distribution for WSL that is really cool. You can get it in theĀ Windows Store. Combine Pengwin with X Server, like X410, and you'll have a really great integrated system.

Easily move WSL distributions between Windows systems.

Ana Betts highlights this amazing techniquethat lets you easily transfer your perfect WSL2 distribution from one machine to n another.

wsl --export MyDistro ./distro.tar

# store it somewhere, Dropbox, OneDrive, somewhere else

mkdir ~/AppData/Local/MyDistro
wsl --import MyDistro ~/AppData/Local/MyDistro ./distro.tar --version 2 

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

Use the Windows Git Credential Provider inside WSL

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

Give it a try, install WSL,Ā Windows Terminal, and createĀ a brilliant Linux environment on Windows..

Source: habr.com

Buy reliable website hosting with DDoS protection, VPS VDS servers šŸ”„ Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster