How to run WSL commands from PowerShell?

QuestionsQuestions8 SkillsProPermissions of FilesOct, 27 2025
0877

To run WSL (Windows Subsystem for Linux) commands from PowerShell, you simply need to use the wsl command followed by the desired command or options. Here’s how to do it:

Basic Syntax

The general syntax for running a command in WSL from PowerShell is:

wsl [options] [command]

Examples

  1. List Installed Distributions:
    To list all installed WSL distributions and their versions:

    wsl -l -v
  2. Start a Specific Distribution:
    To start a specific distribution (e.g., Ubuntu):

    wsl -d Ubuntu
  3. Run a Command in WSL:
    You can run a specific command directly in WSL without starting an interactive shell. For example, to list files in the home directory:

    wsl ls ~
  4. Install a New Distribution:
    To install a new distribution (e.g., Ubuntu):

    wsl --install -d Ubuntu
  5. Access Windows Files from WSL:
    You can access Windows files from WSL by specifying the path. For example, to list files in the C drive:

    wsl ls /mnt/c

Additional Options

  • Run a Command as a Specific User:
    If you want to run a command as a specific user, you can use the -u option:

    wsl -u <username> <command>
  • Terminate a Distribution:
    To terminate a specific distribution:

    wsl --terminate <DistributionName>

Conclusion

You can run WSL commands directly from PowerShell by using the wsl command followed by the desired options or commands. This allows you to manage your WSL environment and execute Linux commands without needing to enter the WSL shell interactively.

0 Comments

no data
Be the first to share your comment!