How to Run Linux Commands on Windows with WSL 2

Windows Subsystem for Linux 2 builds on the success of the original WSL, and the newer WSL 2 brings more power and reliability to users. It is important that you understand how to use Linux commands and utilities on Windows Subsystem for Linux 2.

The following article will show you how to use Linux commands on Windows 10 and 11.

How to get started with WSL 2

Windows Subsystem for Linux 2 is available to users running Windows 10 (Build 19041 or later) and Windows 11; if you're running an earlier version of Windows 10, you'll have to install WSL 2 manually. Fortunately, Microsoft makes it easy to install and set up a Linux distribution in WSL 2. To install WSL 2 with Ubuntu:

1. Launch the Start menu , search for Command Prompt , right-click on the best match and select Run as administrator .

2. Type the following command and press Enter :

wsl - - install

3. The installation will take some time, so you may need to wait. If you want to install another Linux distribution, you can do so with the following command:

wsl - - install -d 

4. You can see the list of Linux distributions through:

wsl.exe -l -o

How to Use Linux Commands on WSL 2

To use Linux commands on Windows, you can use Windows Subsystem for Linux - Linux kernel that integrates directly with the Windows operating system. Here's how you can start using Linux commands and utilities on WSL 2 running Ubuntu:

1. Launch the Start menu , search for Ubuntu and select the best match.

2. Alternatively, you can also launch Ubuntu via the Desktop shortcut .

 

3. Wait for the terminal console to load; when Ubuntu is ready, you will see the words 'Welcome to Ubuntu' on the console.

4. To confirm the installation is complete, type the command below and press Enter :

lsb_release -a

You will now see detailed information about the installed Ubuntu operating system.

Linux has a lot of built-in commands and utilities that can be accessed through the terminal. These commands help you manage the file system, install packages, run applications, edit files, etc. So it's no surprise that the average person prefers to use the Linux command line.

Read on for a list of commands that will help you use the Windows Subsystem for Linux:

  1. cd : is one of the most commonly used Linux commands; help you change directory easily. If you are in the root directory with two root directories, you can switch to another directory by using the cd command as follows:
cd myFolder

To go back one level into the root directory, use the cd command as follows:

cd .
  1. ls : You can use the ls command to see a list of files and directories in the current directory.
  2. mkdir : Similarly if you want to create a new directory use the mkdir command:
mkdir folder_name
  1. cat : To see a preview of the text file on the terminal, you can use the following:
cat text_file.txt
  1. grep : It helps you to search for a specific string in multiple files and is very flexible. You can use it to find matching patterns while perusing the system log files.
  2. touch : You can use the touch command to change the timestamp of a file, but you can also use this command to create a new file by entering the filename as a parameter:
touch newFile.txt
  1. && : This command helps you chain multiple commands together sequentially. For example, to navigate to another directory and create a new file:
cd myFolder && touch newFile.txt
  1. man : The Linux manual is the best place to go when you want to learn how a command or parameter is applied.
  2. clear : Terminal gets very messy, so you can use clear command to clear terminal screen.
  3. wget : The wget tool can be used to download content and files from . It supports , and FTP. You can use wget in its simplest form as follows:

 

wget target_url

If you're new to Linux, you'll probably be overwhelmed by the many commands and utilities that Linux has to offer, but don't worry; Over time, you'll get the hang of it. Before long, you'll be using Linux commands comfortably without resorting to virtual machines or dual-booting.

4.5 ★ | 2 Vote