Skip to main content

Command referencedir

dir command (Windows / CMD)

WindowsCMDfilebeginner

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 / optionMeaning
/AFilter entries by attributes such as hidden or directory.
/BUse bare format with names only.
/O:NSort entries by name.
/SInclude 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.

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.