How to Run Linux Commands on Windows with WSL 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:
- 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 .
- ls : You can use the ls command to see a list of files and directories in the current directory.
- mkdir : Similarly if you want to create a new directory use the mkdir command:
mkdir folder_name
- cat : To see a preview of the text file on the terminal, you can use the following:
cat text_file.txt
- 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.
- 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
- && : 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
- man : The Linux manual is the best place to go when you want to learn how a command or parameter is applied.
- clear : Terminal gets very messy, so you can use clear command to clear terminal screen.
- 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.
You should read it
- 5 Linux commands every sysadmin needs to know
- How to run Linux commands when starting Windows Subsystem for Linux on Windows 10
- Guide to network operation for Linux users: 11 commands to know
- 14 interesting Linux commands in Terminal
- 15 Tar commands should try in Linux
- Useful commands in Unix / Linux
- Basic Linux commands everyone needs to know
- Extremely dangerous commands on Windows, Linux, Mac, don't try even once
- Top 10 examples of Netstat commands on Linux
- 7 commands to manipulate the most basic files and folders everyone must know
- Kali Linux commands from AZ and commonly used commands
- How to run 2 or more Terminal commands at the same time on Linux
Maybe you are interested
How to Listen to FM Radio on Linux
How to switch users on the Linux command line
How to execute Shell script in Linux
AMD Ryzen 9000 CPU runs on Linux for higher performance than Windows 11
New Intel microcode '0x129' tested on Linux, did not show a major impact on performance
How to set up Wireguard VPN on Linux