dir command (Windows / CMD)
What it does
List files and subdirectories with names, dates, sizes, and attributes. Searches for the dir command cmd usually need CMD syntax, practical switches, and notes on how it compares with PowerShell or Linux alternatives. This page covers syntax, common options, and copyable examples for Command Prompt.
List files and subdirectories with names, dates, sizes, and attributes.
Syntax
dir [drive:][path][filename] [/A[[:]attributes]] [/B] [/O[[:]sortorder]] [/S]
Common options
| Flag / option | Meaning |
|---|---|
| /A | Filter entries by attributes such as hidden or directory. |
| /B | Use bare format with names only. |
| /O:N | Sort entries by name. |
| /S | Include matching entries in subdirectories. |
Practical examples
List current folder
dir
Displays entries and free space.
Hidden entries
dir /A:H
Shows entries carrying the hidden attribute.
Recursive file search
dir /S /B *.log
Prints full paths for matching logs.
Linux ↔ Windows equivalent
Closest match: ls (Linux / bash / sh / zsh). List directory entries and inspect file metadata.
Common mistakes
- Using Unix-style `-` options instead of CMD `/` switches.
- Parsing normal formatted output when bare `/B` output is more stable.
Related commands
- cdDisplay or change the current directory in Command Prompt.
- whereLocate matching files, especially executables resolved through PATH.
- Get-ChildItemEnumerate items and child items in filesystem, registry, and other providers.
- lsList directory entries and inspect file metadata.
- cdChange the shell's current working directory.
- findWalk directory trees and select entries using tests and actions.
- rmRemove files and directory trees permanently.
- cpCopy files or directory trees to another location.
FAQ
What does dir do in Command Prompt?
List files and subdirectories with names, dates, sizes, and attributes.
How do I run dir in CMD?
Open Command Prompt and follow `dir [drive:][path][filename] [/A[[:]attributes]] [/B] [/O[[:]sortorder]] [/S]`; quote paths containing spaces.
What is a practical dir example in CMD?
Try `dir` — Displays entries and free space.
Can dir be used in a batch file?
Yes. Check its exit code and escape CMD metacharacters when input is variable.
Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.