dirDIR 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.
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
| Option | Description |
|---|---|
/A | Attribute filter (H, S, D, R, A) |
/B | Bare list format |
/O | Sorting rules |
/S | Include all subfolders |
/P | Pause page by page |
/W | Wide compact layout |
/T | Time 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
DIRwith absolute paths in scripts. - Use
/Bfor stable machine-readable output. - Use
/O:-Dfor incident timelines. - Use
/Aduring 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
| Command | Purpose |
|---|---|
DIR /A:H | Hidden entries |
DIR /A:-D | Files only |
DIR /O:-S | Largest first |
DIR /O:-D | Newest first |
DIR /B /S | Recursive bare export |