How to ls in powershell

Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.

Last updated: April 4, 2026

Quick Answer: In PowerShell, the equivalent of the `ls` command from Unix-like systems is `Get-ChildItem`. This cmdlet lists items in one or more specified locations, such as directories or the registry.

Key Facts

Overview

When transitioning to PowerShell from other command-line interfaces like Bash or the Windows Command Prompt, users often look for familiar commands. The `ls` command, a staple for listing directory contents in Unix-like systems, has a direct counterpart in PowerShell. This article will guide you through using `Get-ChildItem`, the cmdlet that serves as PowerShell's `ls` equivalent, and explore its capabilities and common usage patterns.

What is `Get-ChildItem`?

Get-ChildItem is a PowerShell cmdlet designed to retrieve items and their properties from one or more specified locations. These locations can include the file system (directories and files), the Windows Registry, and other data stores accessible via PowerShell providers. It's the fundamental tool for exploring the structure of your system within the PowerShell environment.

Aliases for `ls` and `dir`

To ease the transition for users accustomed to other shells, PowerShell includes built-in aliases for `Get-ChildItem`. The most common ones are `ls` and `dir`. When you type `ls` in a PowerShell prompt, you are actually executing `Get-ChildItem`. Similarly, `dir` also points to `Get-ChildItem`.

This aliasing means you can often use the commands you're already familiar with. However, understanding the underlying cmdlet, `Get-ChildItem`, is crucial for leveraging the full power of PowerShell.

Basic Usage

The simplest way to use `Get-ChildItem` is to type it without any arguments. This will list the contents of the current directory:

Get-ChildItem# Or using the alias:ls

This command will display the name, last write time, and type of each item in the current directory. For files, the type will be 'File'; for directories, it will be 'Directory'.

Common Parameters and Examples

Listing Contents of a Specific Path

You can specify a path to list the contents of a different directory:

Get-ChildItem C:\Users\YourUsername\Documents# Or:ls C:\Windows

Recursively Listing Items (`-Recurse`)

To list all files and directories within the current directory and all its subdirectories, use the `-Recurse` parameter:

Get-ChildItem -Recurse# Or:ls -Recurse

This can generate a lot of output, so it's often combined with other filtering parameters.

Filtering Items (`-Filter` and `-Include`/`-Exclude`)

You can filter the results based on file names or patterns. The `-Filter` parameter is generally faster as it's processed by the provider:

# List only .txt files in the current directoryGet-ChildItem -Filter "*.txt"# Or:ls -Filter "*.log"

The `-Include` and `-Exclude` parameters work with wildcards and are useful when combined with `-Recurse`:

# List only .ps1 files recursively from the current directoryGet-ChildItem -Recurse -Include "*.ps1"# Or:ls -Recurse -Include "*.config"# List all files except .tmp filesGet-ChildItem -Exclude "*.tmp"

Listing Hidden Items (`-Force`)

By default, `Get-ChildItem` might not show hidden or system files. Use the `-Force` parameter to include them:

Get-ChildItem -Force# Or:ls -Force

Getting More Details (`-Name`, `-File`, `-Directory`)

You can tailor the output to get specific information:

# List only the names of items in the current directoryGet-ChildItem -Name# List only files recursivelyGet-ChildItem -Recurse -File# List only directories in C:\Program FilesGet-ChildItem C:\Program Files -Directory

PowerShell Objects vs. Text Output

A key difference between `ls` in Bash and `Get-ChildItem` in PowerShell is that `Get-ChildItem` returns objects, not just plain text. This means each item listed is an object with properties (like `Name`, `Length`, `LastWriteTime`, `Mode`, `Attributes`, etc.). This allows for powerful manipulation using other PowerShell cmdlets, such as `Where-Object` for filtering or `Sort-Object` for sorting.

For example, to find files larger than 1MB:

Get-ChildItem -File -Recurse | Where-Object {$_.Length -gt 1MB}

This demonstrates the object-oriented nature of PowerShell, which goes far beyond simple text listing.

Beyond the File System

As mentioned, `Get-ChildItem` can be used with other PowerShell providers. For instance, you can list registry keys:

# List items in the HKEY_LOCAL_MACHINE\SOFTWARE registry hiveGet-ChildItem HKLM:\SOFTWARE# Or using the alias:ls HKLM:\SOFTWARE

This flexibility makes `Get-ChildItem` a versatile tool for system exploration.

Conclusion

While the `ls` alias makes it easy to start, understanding and using `Get-ChildItem` directly unlocks the full potential of PowerShell for file system navigation and beyond. Its object-oriented output and extensive parameter set provide a powerful and flexible way to manage and explore your system's contents.

Sources

  1. Get-ChildItem (Microsoft Learn)fair-use
  2. PowerShell - WikipediaCC-BY-SA-4.0
  3. Get-ChildItem (PowerShell) - SS64fair-use

Missing an answer?

Suggest a question and we'll generate an answer for it.