PowerShell: list files
🟢 TIP: Command names and parameter names are case-insensitive.
List Files and Directories
Get-ChildItemhas aliasdir
# list files in current dir dir # full path dir "c:/Program Files/Windows Defender" # relative path dir Documents # using home dir abbrev dir ~/Documents/
If path contain space, need quote.
Wildcard in Path
Path can contain Wildcards such as *.
# list files whose name ends in jpg in current dir dir *jpg
LiteralPath
if you do not want special interpretation of path, use
-LiteralPath.
# list files in a dir whose name is just a asterisk dir -LiteralPath '*'
Show Subdirectories (Recurse and Depth)
list files in current dir, and all subdirectories, any depth:
-recurse
dir -recurse
-depth 0is same as no recurse.-depth 1means include children of first-level subdirectories.-depth 2means up to second-level subdirectories, etc.
dir -depth 1
Show file name only (no dir path)
# list file names dir -recurse -name # result paths are relative to current dir
Show Hidden Files and System Files
dir -Force
Show Only Files (no dir)
dir -file
Show Only Directories
# list only dirs dir -directory
PowerShell. List Dirs and Files
List Dirs
- PowerShell: navigate directory
- PowerShell: show current dir path
- PowerShell: list directories
- PowerShell: show directory as tree
- PowerShell: list empty dir 📜
- PowerShell: dir size 📜
List Files
- PowerShell: list files
- PowerShell: show fullpath, no truncate lines
- PowerShell: list empty files 📜
- PowerShell: count files
- PowerShell: list files by wildcard name pattern
- PowerShell: filter file name by regular expression
- PowerShell: sort files by size
- PowerShell: list large files 📜
- PowerShell: sort files by date
- PowerShell: search text in files (grep)