Getting started with Linux using Windows Subsystem for Linux

Vinayak Tekade
Coder’s Capsule
Published in
9 min readNov 26, 2020

This is a continuation of the series Essential Tools to Learn Before Starting with Software Development, in case you're new to the world of software development and want to know which tools you should learn to get started with it this article might be just for you.

Let’s start with what is Command Line Interface or in short CLI?

Before the development of Graphical User Interface(in short GUI), the only way to interact with our Operating System was using the command line interface which takes in the text input to perform operating systems tasks and give textual output. Before 1960, CLI was the only way to interact with computers. In the 1970s there were many popular CLIs available like UNIX, MS-DOS and Apple DOS. Now with the development of GUI, most of the users never use CLI anymore.

So why should we learn CLI?

CLI is still used by software developers and system administrators to install new software or manage operating system and use features which are not available in GUI.

On top of that, it helps increase productivity as everything is available in one window and we don't have to keep switching between windows or use a mouse to navigate. Despite the steep learning curve, it is totally worth learning CLI even if you have the option to get away without learning it.

For programmers learning CLI is a must as it helps in editing, compiling or building code faster and helps in setting critical parameters which might not be available in GUI.

Okay CLI is great, but why are we focussing on Linux Terminal here?

Linux is the most widely used operating system for servers. All most all the websites you visit are possibly running on Linux servers. And if you are going to write server software that will be running on Linux you might want to deploy to a Linux server itself.
But don't worry, the skills you learn here can be easily transferred to any CLI with hardly any efforts.

Alright that's enough of stories, now lets dive into the actual work

Installation

For this tutorial, we will be using Windows Subsystem for Linux (or WSL). WSL helps us run a Linux environment directly on Windows without the need of a virtual machine. This way we will get the best of both worlds( that's Linux and Windows together)

Step 1: Enable WSL in Settings

Go to your Windows 10 Settings App (Shortcut: Win+I) and go to Apps Section and click on Program and Features on the right side.

A new window with all your installed programs will appear.

Now click on Turn Windows Features on or off

A window with a list of all the windows features will be populated. Search for Windows Subsystem for Linux here, tick the checkbox and click OK.

Now Restart your computer.

Step 2: Install a Linux Distribution

Go to Microsoft Store and search for your favourite Linux Distribution.

For this tutorial, we will be using Ubuntu. Click on Ubuntu and Install.

Step 3: Setup Ubuntu

Now launch Ubuntu on your computer. Create your Username and Password. And you are all set. To check whether everything is working fine type this command and the following output should appear.

wslfetch

Now that we are all set, let's learn some basic Linux commands

1. Navigating around your operating system

Just like how we use the GUI to open, create or remove folders and files. We could use the CLI to do the same.

To view the folder you are currently in, that is the current working directory.

pwd

by default, you will be at the home folder of your user. We could see the content in this directory by using ls command.

ls

By default, the folder will be empty and hence we won't see any output. So let's create a folder by using mkdir command which stands for Make Directory. The syntax is mkdir <foldername>

mkdir folder1
ls

Now when you type ls again you will see the folder name appears. Let’s open this folder and view its content. To open a folder by using cd command which stands for change directory.

cd folder1
ls

Now again this folder is empty, let’s create a file inside it by using the command touch. The syntax is touch <filename with extension>

touch file1.txt file2.cpp file3.html file4.js
ls

Notice that now all the four files with different extensions are created in one command.

Now let’s head back to our previous folder. For this, we use the cd command again. Double periods here are similar to clicking the back button in GUI.

cd ..

Let's add another folder and add files to without changing the folder we are currently in. This possible by entering pathname instead of filename. The single period represents the current working directory here.

mkdir folder2
touch ./folder2/file5.java

Now let’s learn how to delete files and folder. To remove files we could use rm command which stands for remove. The syntax is rm <filename or pathname>

ls ./folder2
rm ./folder2/file5.jsva
ls ./folder2

To delete the folder2 we could use the command rmdir which stands for remove directory. The syntax is rmdir <foldername or pathname>

ls
rmdir folder2
ls

Try the same for folder1 now.

You will receive a similar error. This is because for rmdir to work we need to delete all the contents of the folder first. The best way to delete a folder with all its content is by using a recurring force parameter in rm command.

rm -rf folder1
ls

Now you will find our home directory empty again. And this how we use the basic navigation commands in Linux.

2. File Handling

We learnt how to create a file in the previous section by using the touch command. But empty files are of no use to us. Let’s learn how to deal with these files now.

Use clear command to clear the terminal.

clear

Let’s start by creating a file.

touch file.txt

Ubuntu comes with nano text editor available pre-installed in it. To use it just type nano <filename>. The following interactive shell will open up.

nano file.txt

Let’s type out a demo line inside our file. For Example: “Hello World, I’m Vinayak typing this message inside nano text editor.”

Notice all the options mentioned on the bottom. Use ctrl+<the letter indicated to use them>. To save our file we have an option called write out. To use it press ctrl+O and press enter to save. Now press ctrl+X to exit nano.

To view the content inside our file we will use cat command.

cat file.txt

cat command can also be used for creating a file. Type cat> <filename> content of the file.

cat >file2.txt
This is our second file using cat command

And press ctrl+D to exit.

Let's make a copy of file.txt and store it in another folder. The syntax is cp <path of file to be copied> <path of where the file should be copied>

mkdir folder1
cp file.txt ./folder1/copy.txt
cat ./folder1/copy.txt

Notice how the name of the copied file is changed automatically. We could use mv command to move or even just rename files using this functionality. This can be achieved by using the same pathname.

mv file2 file2.txt
ls
cat file2.txt
mv file2.txt ./folder1/file2.txt
ls
cd folder1
ls

3. System Administration

uptime command shows how long your computer has been running

uptime

whoami command returns the user who is currently logged in your computer

whoami

htop command shows the status of system resources. To exit any command including htop use ctrl+C.

htop

su command gives you superuser rights, that is admin rights.

su

Notice your user changes to root after you run su. Being logged in as superuser gives you access to all admin right.

If you want to run any command with temporary superuser right while you are logged in as a normal user you need to use the prefix sudo before the command. The syntax is sudo <command>

sudo htop

Linux Distributions come with their own application management system and this makes it really easy to install any application on them. To install any software just enter sudo apt-get install <application name>

sudo apt-get install npm

To update all your applications to their latest version. Update gets the list of updates available and upgrade updates them all.

sudo apt-get update
sudo apt-get upgrade

4. Networking

ip command is used for configuring, adding or deleting network/ routing configuration.

ip link show command lists all the available network interfaces

ip link show

ip address command lists all the show all the address and delete or manage old ones

ip address

nmap command is a powerful networking tool used for discovering networks, finding vulnerabilities in a network or just managing networks.

nmap medium.com

ping command is used to check whether a host is receiving or sending packets of data

ping -c 3 google.com

tracerroute command is used to find the missing packets of data and track the source and destination of the data travelled as well.

traceroute google.com

netstat command is used to get statistical data about network connections

netstat -i

ssh enables us to secure connect to networks by using encryption methods and verifying the host.

ssh 10.0.0.50

5. Programming

And of course, if we can create programs using nano and cat. We can also compile them directly in the terminal.

Let's take examples of the hello world program in different languages

To compile a C programming

cc hello.c -o a.out
./a.out

Make sure you have build-essential packages installed

sudo apt-get install build-essential
C program in Linux Terminal

To compile a Python program

python3 hello.py

Make sure you have python3 installed

sudo apt-get update
sudo apt-get install python3.6
Python in Linux terminal

To compile a JavaScript program

node hello.js

Make sure you have NodeJS installed

curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash -
sudo apt-get install -y nodejs
Javascript in Linux Terminal

By now you must have a got an idea of the power of Linux. But this is just the beginning feel free to explore and share your experiences in the comment section.

That’s all for now folks. This is Vinayak Tekade from Coder’s Capsule signing off. Follow me on LinkedIn and Twitter.

Looking forward to learn, teach and grow together. Check us out on Instagram for more similar content.

--

--

Vinayak Tekade
Coder’s Capsule

A young developer looking forward to learn, teach and grow together. Contact me at @VinayakTekade