
If you're a Windows developer who dabbles in Linux (as I've done for the past decade), you might have gone down one of the following paths:
- Install Linux on an old Windows PC, or dual-boot on the same disk.
- Install Oracle's free VirtualBox and then install Linux on a virtual machine (VM).
- Install Hyper-V on Windows Pro and then install Linux on a VM.
Windows Subsystem for Linux
First, head to Programs and Features in the Control Panel and turn on Windows Subsystem for Linux in Windows Features, or run the following PowerShell command in an elevated PowerShell (i.e., run as administrator). In either case, you'll need to do a reboot.Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-LinuxNow we need Linux; I went for Ubuntu, which you can find (surprise!) in the Microsoft Store. Given the history of bad blood between Microsoft and the Linux community, it's an odd feeling to download Linux from that storefront (and it’s a modest download—195 MB). It will only install on a System Drive, so make sure you have the space available. After you've entered a new user name and password, you log in to a bash shell. The first thing I did was the typical sudo apt update, and then upgraded to bring everything up-to-date.
Working with Files
Windows and Linux/Unix have always had their differences when it comes to text files. Windows uses CR/LF (codes 13 and 10) to mark the end of files, whereas Linux uses just LF. But when it comes to files on the WSL subsystem, you must not edit or create them in Windows directly. It's an absolute no, as it will corrupt things and necessitate a Linux reinstall. If you wish to read those files, back up or copy beforehand. On Ubuntu, for instance, the Linux filesystem is located in Windows at:C:\Users\%USERNAME%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\You'll see the same folders as if you did this in Linux:
ls /If you are in Windows and want to run a command quickly on Linux, this is one way to do it:
dir | wsl ls /The command is piped to WSL, which then runs it; so that's the same as ls /.