DEV Community

arnostorg
arnostorg

Posted on

List Files in PowerShell: Get-ChildItem Mastered

List Files in PowerShell: Get-ChildItem Mastered

Get-ChildItem shows you files and folders. Learn the flags that let you see exactly what you're looking for.

How It Works

Get-ChildItem (or ls/dir) is your file explorer from the command line. It shows you what's in a folder, but it has options to filter, hide, and sort files different ways.

By default, it shows files and folders (except hidden ones). With options, you control exactly what appears.

Code Examples

Basic Listing

# See all files and folders in current location
Get-ChildItem

# Shows:
# Mode  LastWriteTime      Length Name
# ----  -------------      ------ ----
# d---- 3/20/2026 10:15 AM        Documents
# -a--- 3/18/2026 2:45 PM  4521   notes.txt
Enter fullscreen mode Exit fullscreen mode

Show Only Files

# Hide folders, show files only
Get-ChildItem -File

# Show only folders
Get-ChildItem -Directory
Enter fullscreen mode Exit fullscreen mode

Filter by Type

# Show only .txt files
Get-ChildItem -Filter "*.txt"

# Show only .xlsx files
Get-ChildItem -Filter "*.xlsx"

# Show all .log files in subfolders too
Get-ChildItem -Filter "*.log" -Recurse
Enter fullscreen mode Exit fullscreen mode

Sort by Date or Size

# Show newest files first
Get-ChildItem | Sort-Object LastWriteTime -Descending

# Show largest files first
Get-ChildItem -File | Sort-Object Length -Descending
Enter fullscreen mode Exit fullscreen mode

Most Used Options

  • -File - Show only files, hide directories
  • -Directory - Show only folders, hide files
  • -Filter '*.txt' - Show only files matching the pattern
  • -Recurse - Look in subfolders too (use with caution on big directories)
  • -Force - Show hidden files that Windows normally hides

The Trick: Power Usage

Find your biggest files: Use this to clean up disk space by finding what takes up room:

Get-ChildItem -File | Sort-Object Length -Descending | Select-Object Name, Length | Select-Object -First 10
Enter fullscreen mode Exit fullscreen mode

This shows your 10 largest files, biggest to smallest. Great for finding what's eating your disk!

Learn It Through Practice

Stop reading and start practicing right now:

👉 Practice on your browser

The interactive environment lets you type these commands and see real results immediately.

Next in PowerShell for Beginners

This is part of the PowerShell for Beginners series:

  1. Getting Started - Your first commands
  2. Command Discovery - Find what exists
  3. Getting Help - Understand commands
  4. Working with Files - Copy, move, delete
  5. Filtering Data - Where-Object and Select-Object
  6. Pipelines - Chain commands together

Related Resources

Summary

You now understand:

  • How this command works
  • The most common ways to use it
  • One powerful trick to level up
  • Where to practice hands-on

Practice these examples until they feel natural. Then tackle the next command in the series.


Ready to practice? Head to the interactive environment and try these commands yourself. That's how it sticks!

What PowerShell commands confuse you? Drop it in the comments!

Top comments (0)