Basic WSL Commands Cheat Sheet š§
List installed Linux distributions
wsl --list --verboseUpdate WSL
wsl --updateCheck WSL status
wsl --statusShutdown
wsl --shutdownImmediately 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
wsl --terminate <Distribution Name>To terminate the specified distribution, or stop it from running, replaceĀ <Distribution Name>Ā with the name of the targeted distribution.
Identify IP address
wsl hostname -I: Returns the IP address of your Linux distribution installed via WSL 2 (the WSL 2 VM address)ip route show | grep -i default | awk '{ print $3}': Returns the IP address of the Windows machine as seen from WSL 2 (the WSL 2 VM)
Export a distribution
wsl --export <Distribution Name> <FileName>Exports a snapshot of the specified distribution as a new distribution file. Defaults to tar format. The filename can beĀ -Ā for standard input. Options include:
--vhd: Specifies the export distribution should be a .vhdx file instead of a tar file (this is only supported using WSL 2)
Import a distribution
wsl --import <Distribution Name> <InstallLocation> <FileName>Imports the specified tar file as a new distribution. The filename can beĀ -Ā for standard input. Options include:
--vhd: Specifies the import distribution should be a .vhdx file instead of a tar file (this is only supported using WSL 2)--version <1/2>: Specifies whether to import the distribution as a WSL 1 or WSL 2 distribution
Import a distribution in place
wsl --import-in-place <Distribution Name> <FileName>Imports the specified .vhdx file as a new distribution. The virtual hard disk must be formatted in the ext4 filesystem type.
Unregister or uninstall a Linux distribution
While Linux distributions can be installed through the Microsoft Store, they canāt be uninstalled through the store.
To unregister and uninstall a WSL distribution:
wsl --unregister <DistributionName>ReplacingĀ <DistributionName>Ā with the name of your targeted Linux distribution will unregister that distribution from WSL so it can be reinstalled or cleaned up.Ā Caution:Ā Once unregistered, all data, settings, and software associated with that distribution will be permanently lost. Reinstalling from the store will install a clean copy of the distribution. For example,Ā wsl --unregister UbuntuĀ would remove Ubuntu from the distributions available in WSL. RunningĀ wsl --listĀ will reveal that it is no longer listed.
You can also uninstall the Linux distribution app on your Windows machine just like any other store application. To reinstall, find the distribution in the Microsoft Store and select āLaunchā.
Mount a disk or device
wsl --mount <DiskPath>Attach and mount a physical disk in all WSL2 distributions by replacingĀ <DiskPath>Ā with the directory\file path where the disk is located. SeeĀ Mount a Linux disk in WSL 2. Options include:
--vhd: Specifies thatĀ<Disk>Ā refers to a virtual hard disk.--name: Mount the disk using a custom name for the mountpoint--bare: Attach the disk to WSL2, but donāt mount it.--type <Filesystem>: Filesystem type to use when mounting a disk, if not specified defaults to ext4. This command can also be entered as:Āwsl --mount -t <Filesystem>.You can detect the filesystem type using the command:Āblkid <BlockDevice>, for example:Āblkid <dev/sdb1>.--partition <Partition Number>: Index number of the partition to mount, if not specified defaults to the whole disk.--options <MountOptions>: There are some filesystem-specific options that can be included when mounting a disk. For example,Ā ext4 mount optionsĀ like:Āwsl --mount -o "data-ordered"Ā orĀwsl --mount -o "data=writeback. However, only filesystem-specific options are supported at this time. Generic options, such asĀro,Ārw, orĀnoatime, are not supported.
Unmount disks
wsl --unmount <DiskPath>Source