Windows CMDInteractive Lab
File Managementdir

DIR Command in Windows: Complete Practical Guide

Master the DIR command in Windows with practical syntax, filters, sorting options, recursive searches, troubleshooting advice, and ready-to-use examples.

Rojan Acharya··Updated Apr 17, 2026
Share

The DIR command in Windows is the built-in CMD utility for listing files and folders, with options for filtering by attributes, sorting by size/date/name, and scanning recursively through subdirectories. It is one of the most used commands for diagnostics, inventory, and script workflows.

What Is DIR in Windows?

DIR is the default directory inspection command in Command Prompt. It helps you confirm file presence, inspect folder contents, and gather output for scripting or reporting.

Syntax

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

Parameters and Options

OptionDescription
/AAttribute filter (H, S, D, R, A)
/BBare list format
/OSorting rules
/SInclude all subfolders
/PPause page by page
/WWide compact layout
/TTime basis (C, A, W)

Examples

DIR
DIR C:\Windows
DIR /A:H
DIR /A:-D /O:-S
DIR /S *.log
DIR /B /S > files.txt

Common Use Cases

  • Verifying deployment files exist.
  • Identifying large files that consume storage.
  • Auditing hidden/system entries.
  • Exporting recursive file inventories.
  • Reviewing latest file modifications.

Tips and Best Practices

  • Pair DIR with absolute paths in scripts.
  • Use /B for stable machine-readable output.
  • Use /O:-D for incident timelines.
  • Use /A during malware triage.

Troubleshooting Common Issues

Access denied

Run elevated CMD and verify NTFS permissions.

Missing expected files

Try DIR /A and confirm you are in the right path.

Too much output

Use wildcard patterns or redirect to file.

Slow recursive scans

Scope path and pattern tightly to reduce traversal.

Related Commands

Frequently Asked Questions

Does DIR work in PowerShell?

Yes, though Get-ChildItem is the native PowerShell equivalent.

How do I list hidden files only?

Use DIR /A:H.

How do I list files only, no folders?

Use DIR /A:-D.

How do I sort by newest file?

Use DIR /O:-D.

How do I recurse subdirectories?

Use DIR /S.

Can I export output?

Yes: DIR /B /S > output.txt.

Is DIR case-sensitive?

No, command switches are case-insensitive.

Which command lists hidden files sorted by size?

DIR /A:H /O:S.

Quick Reference Card

CommandPurpose
DIR /A:HHidden entries
DIR /A:-DFiles only
DIR /O:-SLargest first
DIR /O:-DNewest first
DIR /B /SRecursive bare export

CTA

Try these commands in the simulator, then browse all supported commands in the reference.

Summary

DIR remains the fastest Windows CLI method to inspect files and directories. With /A, /O, /S, and /B, you can handle most listing, audit, and scripting tasks cleanly.