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 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 “purely” move data between worlds. It's not the kind of experience you can easily have with full-fledged virtual machines, and it speaks to the tight integration of Linux and Windows.

Read more about some cool things you can do when mixing peanut butter and chocolate below!

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

Launch Windows Explorer from Linux and access your distribution's files

When you are at the WSL/bash command prompt and want to visually access your files, you can run "explorer.exe ." where the current directory is and you will get a windows explorer window where your Linux files will be delivered to you via the server local network plan9.

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

Use real Linux commands (not CGYWIN) from Windows

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

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

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 because the path to Windows is in $PATH before Windows. All you have to do is explicitly call it with an .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 access your Linux apps 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 on Linux with a VS Code client on the Windows world.

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

Here is a great selection of articles from the Windows Command Line Blog.

Here are the benefits of WSL 2

  • Virtual machines are resource intensive and create a very independent experience.
  • The original WSL was very "connected" but had pretty poor performance compared to a VM.
  • WSL 2 offers a hybrid approach with lightweight VMs, a fully connected interface, and high performance.

Run multiple Linux in seconds

Here I am using "wsl --list --all" and I already have three Linuxes on my system.

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

I can easily run them and also assign profiles to show up in my Windows Terminal.

Run X Windows Server under Windows with Pengwin

Penguin is a special WSL Linux distribution that is very cool. You can get it at Windows Store. Combine Pengwin with X Server like X410, and you get a very cool integrated system.

Easily move WSL distributions between Windows systems.

Ana Betts celebrates this great technique, with which you can easily transfer your ideal WSL2 distribution from one machine to n cars.

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 in sync across all your systems.

Use the Windows Git Credential Provider inside WSL

All of the above features are woven into the climax in this cool post from Ana Bettswhere it integrates 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 a clean and tight integration.

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

Source: habr.com

Add a comment