A kick-start to use Linux with Windows (WSL)!

A kick-start to use Linux with Windows (WSL)!

I just recently was able to secure an internship for this Summer, 2022, yaay :) However, the moment I started I knew that most of my work would require me to have Linux not Windows and my past experience with Linux was honestly not so good. When I used Linux before, I used it with the Linux virtual machine (VM) and it wasn't pretty good, it slowed down my device, always kept freezing so I had to restart it a lot, let alone trying to even exit it was torture :( so it was just a big no but I didn't know I had another choice back then other than the dual boot operating systems which also sounded too complex.

nope-the-office.gif

Back to my internship, my mentor told me I can just run it on WSL (the Windows Subsystem for Linux), I looked it up, understood what it's about then started running it. I've been working with it for over a week now and it's actually going pretty smoothly so far. So I decided to write this blog to walk anyone through how it works and some Linux commands I found useful.

side note: I'm using Windows 11 but my colleague uses Windows 10 and has done the same steps as mine yet it's working just fine with her as well.

What is WSL?

Windows Subsystem For Linux (WSL) is a tool provided by Microsoft to run Linux natively on Windows. It’s designed to be a seamless experience, essentially providing a full Linux shell that can interact with your Windows filesystem.

wsl 2.png

WSL isn’t a full Linux desktop experience that you might get by running Ubuntu in VirtualBox, for example. It does technically use virtualization for performance reasons, but it’s very different from running a full VM. It’s all managed for you, and just provides a simple shell and environment for you to do your work and use familiar bash commands like git, ssh, and all the other tools that come with the chosen distribution.

How to install WSL

The way I installed it, which was very fast, was through the Command Prompt (CMD). To do this, open the Start menu (or press the Windows key) and type cmd to search for the Command Prompt to open a new PowerShell window. Hover over your result and select run as administrator.

wsl 1.png

In your Command Prompt window, you’re able to install and enable WSL with a single simple command. To do this, type the following command and hit enter:

wsl --install

After you enabled WSL, a reboot is required for it to take effect.

Now, let's talk about which Linux distribution you'd like to use. Type the following, replacing distro with the name of the Linux distribution you wish to install:

wsl --install -d distro

For me, I wanted to install Ubuntu so I typed the following:

wsl --install -d Ubuntu

side note: I'll talk about different Linux distributions later on after being done with the installation steps.

Afterwards, you'll be asked to enter your username (it doesn't need to be the same as your Windows username), the password and password confirmation then you're ready to go.

To run Ubuntu now, all you need to do is click on the start menu and you'll find it under recently added or recommendations, click on it and voila, you have it!

jim-halpert-yes.gif

You can also access all your Linux files by opening your file explorer then you'll find a new Linux option on the left, expand it and here are all your files in the Ubuntu folder.

wsl 4.png

Now let's get back to what we left off, Linux distributions.

What is a Linux distribution?

A Linux distribution (known as distro) is an operating system made from a software collection that includes the Linux kernel and often a package management system. Linux users usually obtain their operating system by downloading one of the Linux distributions, which are available for a wide variety of systems ranging from embedded devices and personal computers to powerful supercomputers.

What are the available Linux distributions?

  • Ubuntu: is an open source Debian-based Linux distribution. Sponsored by Canonical Ltd., Ubuntu is considered a good distribution for beginners. The operating system was intended primarily for personal computers but it can also be used on servers.

  • OpenSUSE Leap 42: is compatible with SUSE Linux Enterprise; this gives Leap a level of stability unmatched by other Linux distributions and provides users the ability to migrate to an enterprise offering.

  • SUSE Linux Enterprise Server 12 (SLES): is a secure, adaptable and easy-to-manage Linux server platform that allows developers and administrators to deploy business-critical workloads on-premises, in the cloud and at the edge.

  • Kali Linux: is an open-source, Debian-based Linux distribution geared towards various information security tasks, such as Penetration Testing, Security Research, Computer Forensics and Reverse Engineering.

  • Debian GNU/Linux: is the primary Debian distribution and the only distribution that has been officially released and considered ready for production. References to the Debian OS typically refer to Debian GNU/Linux, which is based on the Linux kernel.

Linux commands that I found helpful

1) pwd command: Use the pwd (print working directory) command to find out the path of the current working directory (folder) you’re in. The command will return a full path, which is basically a path of all the directories that starts with a forward slash (/), as follows:

wsl 5.png

2) mkdir command: Use mkdir (make directory) command to make a new directory (folder) and make sure there is no other directory with the same name exists, as follows:

wsl 6.png

3) cd command: Use the cd (change directory) command to navigate through the Linux files and directories. It requires either the full path or the name of the directory, depending on the current working directory that you’re in.

There are some shortcuts to help you navigate quickly:

  • cd [directory_name] : to move inside a subdirectory.
  • cd /: this command is used to change directory to the root directory, the root directory is the first directory in your filesystem hierarchy.
  • cd dir_1/dir_2/dir_3: to move inside a directory from a directory.
  • cd ~ or cd: to change directory to the home directory.
  • cd .. : to move to the parent directory of current directory, or the directory one level up from the current directory. “..” represents parent directory.
  • cd “dir name” or cd dir\ name: to navigate to a directory with white spaces, we can use single quotes instead of double quotes.

4) cat command: Use the cat (concatenate) command to list the contents of a file on the standard output (sdout), as follows:

cat filename

It can also be used to create a new file and write in it immediately, as follows:

cat > filename

Then after you finish writing in your file, press enter then ctrl+D to save it.

Here, I first created a file called Hello.txt, saved its contents then listed them.

wsl 9.png

5) df command: Use df (disk filesystem) command to get a report on the system’s disk space usage, shown in percentage and KBs, as follows:

df -h

-h is used to display size in powers of 1024

wsl 10.png

These are the commands that I used so far, there are definitely many more commands than these that can be found easily just by googling them up.

bow-bowing.gif

This is everything I learned so far regarding Linux usage with Windows through WSL and Linux commands which is not much at all, I'm still a beginner discovering all of this but I hope it's of help to anyone :)