Windows CMDInteractive Lab
File Managementdir

DIR Command Switches You Should Know

Understand the most useful DIR command switches in Windows CMD, including /A, /O, /S, /B, /T, and practical combinations for real workflows.

Rojan Acharya··Updated Apr 17, 2026
Share

The DIR command switches control how file and folder listings appear in Windows Command Prompt. Instead of using plain DIR, you can apply switches like /A, /O, /S, and /B to filter attributes, sort results, recurse through subfolders, and generate script-ready output.

If you work with troubleshooting, scripts, or routine file audits, knowing a few switch combinations saves significant time. This guide focuses on the switches people actually use in production support and day-to-day command-line work.

What Are DIR Command Switches?

DIR switches are optional flags prefixed by / that change listing behavior. They can be stacked in one command, for example DIR /A:-D /O:-S /S.

Syntax

DIR [path] [filename] [/A[:attrs]] [/O[:sort]] [/S] [/B] [/P] [/W] [/T[:field]]

Most Important DIR Switches

/A - Attribute filtering

Use attribute filters like hidden (H) and directory (D) to narrow results.

/O - Sorting

Sort by name, date, extension, or size. Prefix with - to reverse the order.

/S - Recursive listing

Include all subdirectories from the target path.

/B - Bare output

Output names only; ideal for scripts and exports.

/T - Time field

Choose creation, access, or write time when displaying/sorting by date.

Examples

DIR /A:H
DIR /A:-D /O:-S
DIR C:\Projects /S *.ts
DIR /B /S > inventory.txt
DIR /T:C /O:D
DIR /O:GN

Common Use Cases

  • Find hidden files quickly: DIR /A:H.
  • Identify largest files first: DIR /A:-D /O:-S.
  • Inventory an entire repository: DIR /B /S.
  • Show only folder structure entries: DIR /A:D.
  • Sort by most recent file changes: DIR /O:-D.

Tips and Best Practices

  • Use /B when piping to other commands.
  • Start with path + pattern for cleaner output.
  • Use DIR /A during forensic checks.
  • Avoid over-combining switches unless needed.

Troubleshooting Common Issues

No files shown

Use DIR /A because hidden/system files may be excluded.

Output too long

Use /P or redirect to a file.

Wrong order

Confirm /O value and - direction.

Permission errors

Run elevated CMD if folder ACLs require it.

Related Commands

Frequently Asked Questions

Which DIR switch shows hidden files?

Use /A:H.

Which switch lists only files?

Use /A:-D.

How do I sort by file size?

Use /O:S or /O:-S.

How do I recurse all subfolders?

Use /S.

What does /B do in DIR?

It removes headers and details, outputting names only.

How do I sort by newest files first?

Use /O:-D.

Can I combine DIR switches?

Yes, for example: DIR /A:-D /O:-S /S.

Is DIR available on Windows Server?

Yes, across Windows desktop and server releases.

Quick Reference Card

SwitchPurposeExample
/A:HHidden filesDIR /A:H
/A:-DFiles onlyDIR /A:-D
/O:-SLargest firstDIR /O:-S
/SRecursiveDIR /S
/BBare outputDIR /B /S

Try in Simulator

Practice switch combinations safely in the Windows Command Simulator and explore more syntax in the Commands Reference.

Summary

DIR command switches are the difference between basic listing and targeted file analysis. Learn /A, /O, /S, and /B first, then combine them for faster troubleshooting, scripting, and cleanup.