Using Linux on Windows via WSL
Richard Harris
DevOps, Online & Mobile at TD Bank Group #devops #agile #cloud #java #js #csharp
Contents
??
Overview of Windows Subsystem for Linux (WSL)
Developers can access the power of both Windows and Linux at the same time on a Windows machine. The Windows Subsystem for Linux (WSL) lets developers install a Linux distribution (such as Ubuntu - the default distro, OpenSUSE, Kali, Debian, Arch Linux, etc) and use Linux applications, utilities, and Bash command-line tools directly on Windows, unmodified (Linux binaries), without the overhead of a traditional virtual machine or dualboot setup.
WSL2 was announced at Microsoft Build 2019. WSL2 features a Linux kernel running inside Windows 10+ and is built on the core technology of Hyper-V to provide better Linux application support and improved file performance.
Install a complete Ubuntu terminal environment (Ubuntu 22.04.2 LTS) in minutes with Windows Subsystem for Linux (WSL). You can install Linux specific frameworks or frameworks that function great on Linux, like Python, Go and REST without impacting your local Windows setup whatsoever.
WSL 2 is only available in Windows 11 or Windows 10, Version 1903, Build 18362 or later.
?WSL architecture: Linux Distribution ??WSL ? Windows NT Kernel
?
History
Key Features
Recommended YouTube Videos
?
Why would you want to use Linux tools on Windows?
A lot of programming languages and frameworks like Python, C, and even things like Node are really designed and built with Linux in mind. It's great to be able to use these tools in their native environment, but still interact within Windows, giving you the best of both worlds. Now you?an use Bash and other command line tools within WSL, inside of a window on your Windows box.
?You can:
Why would I use WSL rather than Linux in a VM?
A traditional VM experience can be slow to boot up, is isolated, consumes a lot of resources, and requires your time to manage it. WSL 2 does not have these attributes.
WSL requires fewer resources (CPU, memory, and storage) than a full virtual machine. WSL also allows you to run Linux command-line tools and apps alongside your Windows command-line, desktop and store apps, and to access your Windows files from within Linux (and vice versa). This enables you to use Windows apps and Linux command-line tools on the same set of files if you wish.?The Integration & File Access make WSL better than Dual Booting or Virtual Machines.
?WSL is a great way to have the best of Linux and Windows all in one.
Comparing WSL 1 and WSL 2
The primary differences between WSL 1 and WSL 2 are the use of an actual Linux Kernel inside a Managed VM (WSL2), support for full system call compatibility (WSL2), and performance across the Linux and Windows operating systems (WSL1). WSL 2 is the current default version when installing a Linux distribution and uses the latest and greatest in virtualization technology to run a Linux kernel inside of a lightweight utility virtual machine (VM).
WSL 2 is only available in Windows 11 or Windows 10, Version 1903, Build 18362 or later.
?Full Linux kernel
The Linux kernel in WSL 2 is built by Microsoft from the latest stable branch, based on the source available at kernel.org. This kernel has been specially tuned for WSL 2, optimizing for size and performance to provide an amazing Linux experience on Windows. The kernel will be serviced by Windows updates, which means you will get the latest security fixes and kernel improvements without needing to manage it yourself.
The WSL 2 Linux kernel is open source. If you'd like to learn more, check out the blog post Shipping a Linux Kernel with Windows written by the team that built it.
See Also
Setup (including key Linux & PowerShell commands)
How-To Setup WSL2
?1) Turn the following Windows Features On:
?Note: VmmemWSL Windows Process (tiny virtual machine)
?2) The following are available for download and setup via Microsoft Store:
Alternatively, the following links will open the Microsoft store page for each distribution:
Note: Windows Terminal is an improved command line shell that allows you to run multiple tabs so that you can quickly switch between Linux command lines, Windows Command Prompt, PowerShell, Azure CLI, or whatever you prefer to use.
Tip: Within WSL, you can use Linux distributions found outside of the Microsoft Store. Microsoft has added the ability to import your own distributions. All you need is a tar ball of the Linux binaries inside of that distro.
?3) Enable GUI Application support by installing:
Once the process of installing your Linux distribution with WSL is complete, open the distribution (Ubuntu by default) using the Start menu. You will be asked to create a User Name and Password for your Linux distribution.
See Also
?
Ways to run Linux distributions with WSL
WSL supports running as many different Linux distributions as you would like to install. This can include choosing distributions from the Microsoft Store, importing a custom distribution, or building your own custom distribution.
?There are several ways to run your Linux distributions once installed:
??
Windows PowerShell Commands for WSL
The WSL commands below are listed in a format supported by PowerShell or Windows Command Prompt. To run these commands from a Bash / Linux distribution command line, you must replace wsl with wsl.exe. For a full list of commands, run:
>?wsl --help
Tip: Now you can use Bash and Powershell together for scripting (i.e. Powershell can invoke Bash scripts).
??
Install WSL and set the default distribution of Linux
> wsl --install
?> wsl --install <Distribution Name>
> wsl --install -d <Distribution Name>
> wsl --set-default <Distribution Name>
The --install command performs the following actions:
Note: You will need to restart your machine during this installation process.
?
Set default version to WSL1 or WSL2 via Version# parameter
> wsl --set-default <Distribution Name> <Version#>
?Example:
> wsl --set-default Ubuntu-20.04 2
??
List available Linux distributions
> wsl -l -o
> wsl --list --online
The following is a list of valid distributions that can be installed.
Install using 'wsl.exe --install <Distro>'.
NAME?????????????????????????????????????????FRIENDLY NAME
Ubuntu???????????????????????????????????????Ubuntu
Debian????????????????????????????????????????Debian GNU/Linux
kali-linux?????????????????????????????????????Kali Linux Rolling
Ubuntu-18.04????????????????????????????Ubuntu 18.04 LTS
Ubuntu-20.04????????????????????????????Ubuntu 20.04 LTS
Ubuntu-22.04????????????????????????????Ubuntu 22.04 LTS
OracleLinux_7_9????????????????????????Oracle Linux 7.9
OracleLinux_8_7????????????????????????Oracle Linux 8.7
OracleLinux_9_1????????????????????????Oracle Linux 9.1
openSUSE-Leap-15.5?????????????????openSUSE Leap 15.5
SUSE-Linux-Enterprise-Server-15-SP4???SUSE Linux Enterprise Server 15 SP4
SUSE-Linux-Enterprise-15-SP5?SUSE Linux Enterprise 15 SP5
openSUSE-Tumbleweed????????????openSUSE Tumbleweed
See Also
?
List installed Linux distributions
> wsl -l
> wsl --list
Windows Subsystem for Linux Distributions:
Ubuntu-22.04 (Default)
?
> wsl -l -v
> wsl --list --verbose
?NAME???????????STATE??????????VERSION
* Ubuntu-22.04???Running????????2
?
> wsl --list --running
Windows Subsystem for Linux Distributions:
Ubuntu-22.04 (Default)
Run a specific Linux distribution?from PowerShell
> wsl --distribution <Distribution Name>
> wsl --distribution <Distribution Name> --user <Username>
> wsl --d <Distribution Name>
?Example:
> wsl -d Ubuntu-22.04
> wsl -d CentOS
?
Run as a specific user
> wsl --user <Username>
> wsl -u <Username>
?
Manually Update to the latest Kernal
> wsl --update
?
Uninstall a WSL Distribution
> wsl --unregister <distroName>
?
WSL - Update / Check status / Check WSL version / Help command
> wsl --status
> wsl --version
> wsl --help
> wsl --shutdown
> wsl --terminate <Distribution Name>
> wsl --mount <DiskPath>
> wsl --unmount <DiskPath>
Shutdown immediately terminates all running distributions and the WSL 2 lightweight utility virtual machine. This command may be necessary in instances that require you to restart the WSL 2 virtual machine environment, such as changing memory usage limits or making a change to your .wslconfig file.
Terminate stops the specified distribution from running.
Note: VmmemWSL Windows Process (tiny virtual machine)
??
Check Available Disk Space
> wsl.exe --system -d <distribution-name> df -h /mnt/wslg/distro
> wsl.exe --system -d Ubuntu-22.04 df -h /mnt/wslg/distro
??
Locate the .vhdx file and disk path for your Linux distribution
> (Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq '<distribution-name>' }).GetValue("BasePath") + "\ext4.vhdx"
> (Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq 'Ubuntu-22.04' }).GetValue("BasePath") + "\ext4.vhdx"
See Also
?
Linux Shell Commands
Print LSB (Linux Standard Base) and Distribution Information (description & codename)
$ lsb_release -dc
Description:???Ubuntu 22.04.2 LTS
Codename:??????jammy
??
Check Linux distro currently Running
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:???Ubuntu 22.04.2 LTS
Release:???????22.04
Codename:??????jammy
?
Check Linux Kernal Version
$ uname -a
Linux DESKTOP-RQ9I2MJ 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
??
See services running
$ service --status-all
$ systemctl list-unit-files --type=service
??
View Linux Processes
htop
??
System Info
$ sudo apt install neofetch
$ neofetch
?
Display Fortune on Startup
Install:
sudo apt install fortune cowsay
Add to bottom: .bashrc: fortune | cowsay
$ sudo nano ~/.bashrc
Suppressing the sudo password prompt
$ sudo visudo
Add to bottom: linuxadmin ALL=(ALL) NOPASSWD: ALL
??
List Packages
$ apt list
??
List Installed Packages
$ apt list --installed
$ apt list neofetch
??
Install Software
$ sudo apt install <name>
$ sudo apt-get install <app_name>
??
Update and upgrade packages
It is recommended that you regularly update and upgrade your packages using the preferred package manager for the distribution. For Ubutu and Debian, use the command (to update programs that have already been installed):
$ sudo apt update && sudo apt upgrade
Windows does not automatically update?or upgrade your Linux distribution(s). This is a task that most Linux users prefer to control themselves.
?
Update the list of software available
$ sudo apt update
$ sudo apt-get update
?
Downloads the package lists from the repositories and updates them
$ sudo apt upgrade -y
?
To add wget (to retrieve content from web servers) and ca-certificates (to allow SSL-based applications to check for the authenticity of SSL connections), enter:
$ sudo apt-get install wget ca-certificates
??
List the available filesystems in WSL2
$ cat /proc/filesystems
??
Check Current Version of Linux Kernal
$ cat /proc/version
Note: The Linux kernel used by WSL is updated automatically.
?
Obtain IP address of your Linux Distribution
$ cat /etc/resolv.conf
??
Editing the file to add systemd to WSL2
systemd is a suite of basic building blocks for a Linux system.
The latest install of WSL2 already has this enabled by default.
?$ sudo nano /etc/wsl.conf
?[boot]
systemd=true
?
WSL Linux-Windows Integration & File Access
How do I access Files on my computer in WSL?
Mount points for hard drives on the local machine are automatically created and provide easy access to the Windows file system from within Linux.
Syntax: /mnt/<drive letter>/
Example: > Access c:\ drive: /mnt/c
WSL Prompt: $ ls /mnt/c
View all of your available Linux distributions and their root file systems from within Windows.
Windows Explorer: \\wsl$\
Syntax: \\wsl$\[distroname]
Example: \\wsl$\Ubuntu-22.04\home\richard
Powershell Prompt: PS > dir \\wsl$\Ubuntu-22.04\home\richard
Tip: After installing WSL, you'll notice a 'Linux' option on the left side of Windows File Explorer.
Tip: Store your project files on the same operating system as the tools you plan to use. For the fastest performance speed, store your files in the WSL file system if you are working on them with Linux tools in a Linux command line (Ubuntu, OpenSUSE, etc). If you're working in a Windows command line (PowerShell, Command Prompt) with Windows tools, store your files in the Windows file system. Files can be accessed across the operating systems, but it may significantly slow down performance.
See Also
?
Integration
WSL allows you to run Linux commands in Windows, and Windows commands within Linux.
Run Windows tool directly from WSL command line (text file is a Linux file)
$ notepad.exe HelloWorld.txt
Launch Windows File Explorer from within WSL
$ explorer.exe .
Note: Remember to include .exe at the end
Launch nautilus Linux File Explorer showing Linux files
$ sudo apt install nautilus
$ nautilus . &
?
Launch nautilus Linux File Explorer showing Windows files
$ nautilus /mnt/c &
?
Run Linux tools from a Windows command line
> wsl.exe ls -la
...
drwxrwxrwx 1 richard richard????512 May 14 17:32?Desktop
drwxrwxrwx 1 richard richard????512 May?2 19:20?Documents
drwxrwxrwx 1 richard richard????512 May 14 17:26?Downloads
drwxrwxrwx 1 richard richard????512 May?2 19:36?Dropbox
drwxrwxrwx 1 richard richard????512 Apr 29 17:11?Favorites
...
drwxrwxrwx 1 richard richard????512 Apr 29 17:11?Music
lrwxrwxrwx 1 richard richard?????30 Apr 29 17:11 'My Documents' -> /mnt/c/Users/Richard/Documents
...
drwxrwxrwx 1 richard richard????512 May 14 17:34?OneDrive
drwxrwxrwx 1 richard richard????512 Apr 30 02:04?Pictures
...
?
Mixing Linux and Windows commands?
To use the Linux command ls -la to list files and the PowerShell command findstr to filter the results for words containing "git", combine the commands:
> wsl ls -la | findstr "Edge"
-rwxrwxrwx 1 richard richard??2361 Apr 29 17:16 Microsoft Edge.lnk
To use the PowerShell command dir to list files and the Linux command grep to filter the results for words containing "git", combine the commands:
> dir | wsl grep git
Run Windows tools from Linux
To run the Windows tool ipconfig.exe, use the Linux tool grep to filter the "IPv4" results, and use the Linux tool cut to remove the column fields, from a Linux distribution (for example, Ubuntu) enter:
$ ipconfig.exe | grep IPv4 | cut -d: -f2
Let's try an example mixing Windows and Linux commands. Open your Linux distribution (ie. Ubuntu) and create a text file: touch foo.txt. Now use the Linux command ls -la to list the direct files and their creation details, plus the Windows PowerShell tool findstr.exe to filter the results so only your foo.txt file shows in the results:
$ ls -la | findstr.exe foo.txt
Windows tools must include the file extension, match the file case, and be executable. Non-executables including batch scripts. CMD native commands like dir can be run with cmd.exe /C command.
?
Open a Remote WSL folder From VS Code (after installing WSL, VS Code, and WSL Extension)
CTRL+SHIFT+P > "WSL" > WSL: Connect to WSL
From there you can Open a folder or Terminal Window in your WSL session
Note: Share environment variables between Windows and WSL with WSLENV
?
See Also
?
Running Graphical Linux Applications
The?X Window System Architecture?allows running the X server and the X clients on separate systems and in WSL's case the X server can be a native Windows server providing even OpenGL acceleration and the clients can be the graphical Linux applications running in the WSL environment.
Install one from several X servers available for Windows and start it before entering the WSL environment:
If graphical applications can't connect to the running X server automatically paste the following commands to the terminal before starting the applications or set them on every login by adding them to?~/.bashrc:
export DISPLAY=:0 # in WSL 1
export DISPLAY=$(awk '/nameserver / {print $2; exit}'/etc/resolv.conf 2>/dev/null):0 # in WSL 2
export LIBGL_ALWAYS_INDIRECT=1
Tip: To add the path permanently, add the above lines to the end of ~/.bashrcfile via - sudo nano ~/.bashrc
See Also
?
Sample GUI App
Rather than modify ~/.bashrc (previous section), you can also run the export command directly from the command line in order to enable GUI applications (you need to be running VcXsrv > XLaunch):
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
If an App is running from Linux, your Windows taskbar will show a Tux (penguin) icon.
?You can even Copy & Paste between Linux & Windows GUI Apps.
$ sudo apt install x11-apps
$ xeyes &
??
Sample Linux Applications
Linux File Explorer
$ sudo apt install nautilus
$ nautilus
??
Install Google Chrome for Linux
To install the Google Chrome for Linux:
?
To launch, enter:
$ google-chrome
??
Rhythmbox Audio Player
GUI Support also includes Audio Support (including microphone).
Rhythmbox is an opensource and easy-to-use audio player that ships by default with Linux systems running the GNOME desktop environment.
$ sudo add-apt-repository ppa:ubuntuhandbook1/apps
$ sudo apt-get update
$ sudo apt-get install rhythmbox
$ rhythmbox
$ rhythmbox music/file_example_MP3.mp3 &
?
Other Notable Linux Applications
$ sudo apt install gedit -y
$ sudo apt install gimp -y
$ sudo apt install vlc -y
?
领英推荐
Linux Console Games
$ sudo apt-get install pacman4console
$ pacman4console
$ sudo apt-get install moon-buggy
$ moon-buggy
$ sudo apt-get install ninvaders
$ ninvaders
?
Development
C Programming
$ sudo apt install gcc
$ gcc --version
$ touch helloworld.c
$ nano helloworld.c
$ gcc helloworld.c -o helloworld
$ ./helloworld
Alternatively:
$ sudo apt-get install gcc
Note: Two popular editors directly in Linux are vi and nano. gedit is a Linux GUI application that is similar to Notepad++.
Code Snippet: ?
<stdio.h>
int main()
{
???printf("Hello World!\n");
?
???for(int i=1; i<=10;i++)
???????printf("%d\n",i);
?
???return 0;
}
?
See Also
?
NIM
Install
$ git clone https://github.com/nim-lang/Nim.git
$ cd Nim
$ ./build_all.sh
?
Add NIM to PATH
You can add only a directory path to path variable. Run the below commands on terminal to add a directory path to the PATH-Variable:
PATH=$PATH:/path/to/the/directory
To add the path permanently, add the following line at the end of ~/.bashrc file
sudo nano ~/.bashrc
Add the below line at the end…
Syntax:
export PATH=$PATH:/path/to/the/directory
Example:
export PATH=$PATH:/home/richard/.nimble/bin:/home/richard/Nim/bin
?
Code Example:
$ nano helloworld.nim
$ nim compile helloworld.nim
$ ./helloworld
?
Code Snippet:
echo "Hello World!"
for i in countup(1, 10):
?echo i
Source: https://github.com/nim-lang/Nim
See Also: https://wiki.ubuntu.com/WSL#Hello_World
??
Python
$ sudo apt update
$ sudo apt install python3 python3-pip
$ python3 --version
$ nano helloworld.py
$ python3 helloworld.py
?
Code Snippet:
print("Hello World!")
i = 1
while i <= 10:
???????print(i)
???????i += 1
?
Visual Studio Code Remote Development
VS Code Remote Development allows you to use a container, remote machine, or the Windows Subsystem for Linux (WSL) as a full-featured development environment. Essentially just the VS GUI would run in Windows, but the rest would run in Linux.?
When using Remote - WSL (VS Code Extension - see below), Open Folder looks at remote files, and VS Code Terminal allows you to run Linux commands within VS Code.
?
Remoting into other machines
Benefits
Terms
Tip: You can SSH from Windows Powershell. Another great SSH client is Putty.
??
VS Code Extensions
Use the VS Code Remote WSL Extension to enable you to store your project files on the Linux file system, using Linux command line tools, but also using VS Code on Windows to author, edit, debug, or run your project in an internet browser without any of the performance slow-downs associated with working across the Linux and Windows file systems.
?
Open a Remote WSL folder From VS Code
CTRL+SHIFT+P > "WSL" > WSL: Connect to WSL
Or
Select 'Open a Remote Window' via the green button in the bottom left of VS Code, then select 'Connect to WSL'
From there you can Open a folder or Terminal Window in your WSL session
??
Open a Linux text file in VS Code from WSL
$ code ./HelloWorld.txt
?
Open a WSL project in Visual Studio Code
$ cd my [AppDir]
$ code .
?
Open a text file in Linux gedit from WSL
$ gedit ./HelloWorld.txt
?
See Also
?
Advance Setup: Developer Tools
Recommended Tools / Tutorials
?
Installing Git
$ sudo apt-get install git
$ git config --global user.name "richard"
$ git config --global user.email "[email protected]"
$ git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/bin/git-credential-manager.exe"
$ git config --global credential.https://dev.azure.com.useHttpPath true
$ add-apt-respository ppa:git-core/ppa
?
$ cat ~/.gitconfig
$ git --version
??
Installing MySQL
$ sudo apt update
$ sudo apt install mysql-server
$ mysql --version
?
$ sudo /etc/init.d/mysql start
$ sudo /etc/init.d/mysql stop
?
$ systemctl status mysql
$ sudo mysql
?
SHOW databases;
CREATE DATABASE [database_name];
USE [database_name];
SHOW tables;
?
Note: Default admin user is root
?
Installing Postgres
$ sudo apt install postgresql postgresql-contrib
$ psql --version
?
$ sudo service postgresql status
$ sudo service postgresql start
$ sudo service postgresql stop
?
$ sudo passwd postgres
?
$ sudo -u postgres psql
?
postgres=# \q
?
Note: Default admin user is postgres
?
Installing SQLite
$ sudo apt update
$ sudo apt install sqlite3
$ sqlite3 --version
$ sqlite3 TestDB.db
$ .databases
$ CREATE TABLE empty (kol INTEGER);
$ .tables
$ .schema empty
$ .exit
?
Installing Redis
sudo apt update
sudo apt install redis-server
redis-server --version
sudo service redis-server start
redis-cli ping
sudo service redis-server stop
?
Installing Docker
Docker is a tool used to create, deploy, and run applications using containers. Containers enable developers to package an app with all of the parts it needs (libraries, frameworks, dependencies, etc.) and ship it all out as one package. Using a container ensures that the app will run the same regardless of any customized settings or previously installed libraries on the computer running it that could differ from the machine that was used to write and test the app's code. This permits developers to focus on writing code without worrying about the system that code will be run on.
Docker containers are similar to virtual machines, but don't create an entire virtual operating system. Instead, Docker enables the app to use the same Linux kernel as the system that it's running on. This allows the app package to only require parts not already on the host computer, reducing the package size and improving performance.
Steps:
$ docker run hello-world
Note: You must be running Docker Desktop (Docker Engine) for this command to work.
?
Docker creates two distro folders to store data:
\wsl$\docker-desktop
\wsl$\docker-desktop-data
Note: These folders are visible via Windows File Explorer > Linux
?
See Also
?
VS Code Sample using Extensions - WSL & Dev Containers & Docker
To get started developing apps using Docker with WSL 2, it's recommended that developers use VS Code, along with the WSL, Dev Containers, and Docker extensions.
Install the VS Code WSL extension. This extension enables you to open your Linux project running on WSL in VS Code (no need to worry about pathing issues, binary compatibility, or other cross-OS challenges).
Install the VS Code Dev Containers extension. This extension enables you to open your project folder or repo inside of a container, taking advantage of Visual Studio Code's full feature set to do your development work within the container.
Install the VS Code Docker extension. This extension adds the functionality to build, manage, and deploy containerized applications from inside VS Code. (You need the Dev Containers extension to actually use the container as your dev environment.)
?
Installing Django
Pre-requisite: Python (see - Development > Python)
?
Install Django:
$ sudo apt install python3-django
$ django-admin --version
?
Download a sample project and open it in VS Code (WSL Extension):
$ cd helloworld-django/
$ pip install Django
$ python3 manage.py runserver
?
Then in your web browser go to: https://127.0.0.1:8000/
?
See Also
?
?
Installing NodeJS
$ sudo apt-get install curl
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
$ command -v nvm
$ nvm ls
$ nvm install --lts
$ nvm ls
$ node --version
$ npm --version
Note: To verify installation, enter: command -v nvm - this should return 'nvm', if you receive 'command not found' or no response at all, close your current terminal, reopen it, and try again.
Then install VS Code Extension - Node Extension Pack
?See Also
?
Check services running
?$ service --status-all
Tip: For log commands like starting services, you can create aliases in your .profile file.
See Also
??
Getting Started with Bash
$ pwd
$ mkdir [dir_name]
$ cd [dir_name]
$ ls
$ ls -l
$ touch HelloWorld.txt
$ nano HelloWorld.txt
$ gedit HelloWorld.txt
$ cat HelloWorld.txt
$ tail -20 ~/.bashrc
?
$ nano fruits.txt
$ cat fruits.txt
$ cat fruits.txt | sort
$ cat fruits.txt | grep P
$ cat fruits.txt | sort > sorted_fruit.txt
$ cat sorted_fruit.txt
??
Quick Reference
Running Distributions other than Ubuntu
?Refer to these sections:
??
Linux Admin Commands
?See services running
$ service --status-all
$ systemctl list-unit-files --type=service
?
View Linux Processes
$ htop
?
System Info
$ sudo apt install neofetch
$ neofetch
?
List Packages
$ apt list
$ apt list --installed
$ apt list neofetch
?
Install Software
$ sudo apt install <name>
$ sudo apt-get install <app_name>
?
Update the list of software available and upgrade them
$ sudo apt update && sudo apt upgrade
?
Check Current Version of Linux Kernal
$ cat /proc/version
Note: The Linux kernel used by WSL is updated automatically.
?
WSL Linux-Windows Integration & File Access
?File Access from within Linux
/mnt/c
?File Access from within Windows
\\wsl$\
Linux File Explorer
$ sudo apt install nautilus
$ nautilus . &
?
Run Windows tool directly from WSL command line
$ notepad.exe HelloWorld.txt
Run Linux tools from a Windows command line
> wsl.exe ls -la
?Mixing Linux (i.e. ls) and Windows commands (i.e. findstr)
> wsl ls -la | findstr "Documents"
> dir | wsl grep Documents
??
Open a Remote WSL folder From VS Code (after installing WSL, VS Code, and WSL Extension)
CTRL+SHIFT+P > "WSL" > WSL: Connect to WSL
From there you can Open a folder or Terminal Window in your WSL session
Or
Select 'Open a Remote Window' via the green button in the bottom left of VS Code, then select 'Connect to WSL'
From there you can Open a folder or Terminal Window in your WSL session
?
Open a Linux text file in VS Code from WSL
$ code ./helloworld.py
Open a text file in Linux gedit from WSL
$ gedit ./HelloWorld.txt
Linux Text Editors
$ nano
$ gedit
Key Links
?? Windows Subsystem for Linux (WSL)
How-To
Connect USB
Systemd (required for system services)
?? Ubuntu Tutorials
?? Ubuntu.com
?? Linux Kernal
?? Linux Command Line
?? Windows Terminal
?? Developer Tools
VS Code
SQL Server
?? Videos
?? Data Science | ML | AI
? Ask Ubuntu (Stack Exchange)