dirList Directory in CMD: Simple and Advanced Methods
Learn how to list a directory in CMD using DIR with practical options for hidden files, sorting, recursion, and export to text files.
To list a directory in CMD, use DIR. Add switches like /A, /O, /S, and /B to filter, sort, recurse, and format output for automation.
Basic Command
DIR
Syntax
DIR [path] [pattern] [/A[:attrs]] [/O[:sort]] [/S] [/B] [/P]
Essential Examples
DIR C:\Temp
DIR *.txt
DIR /A:H
DIR /O:-D
DIR /A:-D /O:-S
DIR /S /B > files.txt
Common Use Cases
- Quick check of folder contents.
- Hidden file investigations.
- Recent change review by date sort.
- Large file identification by size sort.
- Script-friendly export for automation.
Tips and Best Practices
- Prefer absolute paths in production scripts.
- Use wildcard filters to narrow output.
- Redirect output for evidence retention.
Troubleshooting
File Not Found
Check path and include /A for hidden/system items.
Too many results
Use *.ext patterns and specific paths.
Access denied
Use elevated CMD if required.
Garbled pipeline output
Switch to DIR /B before piping.
Related Commands
Frequently Asked Questions
What is the command to list files in CMD?
Use DIR.
How do I list hidden files?
Use DIR /A:H.
How do I list files only?
Use DIR /A:-D.
How do I list recursively?
Use DIR /S.
How do I export output?
Use redirection: DIR /B /S > output.txt.
How do I sort by date?
Use DIR /O:-D.
How do I sort by size?
Use DIR /O:S or DIR /O:-S.
Can this run in Windows Terminal?
Yes.
Quick Reference Card
| Command | Purpose |
|---|---|
DIR | Standard listing |
DIR /A:H | Hidden files |
DIR /A:-D | Files only |
DIR /O:-D | Newest first |
DIR /B /S | Recursive bare export |
CTA
Run these commands in the Windows Command Simulator, then browse more examples in Commands Reference.
Summary
DIR is the core CMD command for listing directories and files. Learn a few switch combinations and you can handle most listing tasks quickly.