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
- 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
May be interested
- 7 commands to manipulate the most basic files and folders everyone must knowon windows or linux operating systems, there are a number of things that users can only do with commands. in the following article, the network administrator will introduce you to the 7 most basic commands that any user must 'understand' to perform operations faster.
- Kali Linux commands from AZ and commonly used commandscombining kali linux commands from az comes with some commonly used kali linux commands that make it easy to work with this operating system.
- How to run 2 or more Terminal commands at the same time on Linuxif you use linux, you probably know how to use useful commands to work with files, install software and launch programs. however, one thing you don't know is that you can still run multiple commands at the same time.
- Basic Linux commands everyone needs to know - Operations on Linux are much fasterwhen using linux, you should also learn basic linux commands to perform operations more quickly and easily. below are some basic linux commands you should know.
- 10 most useful Linux commandsfor those who are new to linux, administration will face many difficulties. here are the 10 most useful linux commands that make your administration a lot easier.
- Summary of the common Run CMD commandsinstead of performing manual and direct access operations on windows, we can replace existing cmd commands for faster access.
- How to schedule Linux commands with 'at'utility at very easy to use. users only need to give time and date as command line parameters, then enter one or more commands to execute.
- Linux Error SUDO allows you to run commands as roota flaw in the sudo linux command has been discovered, which may allow non-privileged users to execute commands as root.
- 20+ essential Linux security commandshere are some of the most important security commands for everyday work on linux systems. if you're interested in security issues on your linux system, don't ignore these helpful security commands.
- Basic utilities: print, email in Unixby this chapter, you have a few basic insights about unix systems and some of its basic commands. this chapter will briefly discuss some of the basic but important utilities of unix utilities that you will use in your daily activities.