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
Show Only Files
# Hide folders, show files only
Get-ChildItem -File
# Show only folders
Get-ChildItem -Directory
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
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
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
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:
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:
- Getting Started - Your first commands
- Command Discovery - Find what exists
- Getting Help - Understand commands
- Working with Files - Copy, move, delete
- Filtering Data - Where-Object and Select-Object
- 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)