The Windows DIR command lists files and folders in Command Prompt. Used well, it is faster than clicking through File Explorer — especially when you need hidden files, recursive searches, or script-friendly file lists.
This guide explains what dir does, then covers five switches worth memorizing. For the official switch list, see Microsoft Learn’s DIR command reference.
What does DIR do?
Open Command Prompt and run:
dir
You get every file and folder in the current directory: last write time, size (files), and <DIR> for folders.
That is the whole job: inventory the current folder. Flags change how the inventory is shown and filtered.
DIR vs File Explorer
| Need | Why DIR helps |
|---|---|
| Hidden / system files |
/a surfaces attributes Explorer may hide by default |
Find *.log deep in a tree |
/s recurses without opening every folder |
| Feed a script |
/b prints bare names — one per line |
| Sort by date or size |
/o: sorts without clicking column headers |
5 DIR flags worth memorizing
1. /w — wide view
dir /w
Names in columns, less metadata. Fast visual scan of a crowded folder.
2. /a — include attributes (and hidden items)
dir /a
Without /a, many hidden and system items stay out of the listing. Narrow it:
dir /a:h
Hidden only — useful when a “missing” file is just marked Hidden.
3. /s — search subfolders
dir /s *.log
Lists matches in the current folder and every subfolder. Pair with a pattern when you know the name shape but not the path.
4. /o: — sort the listing
dir /o:n
Common sort keys:
-
/o:n— name -
/o:d— date (oldest first) -
/o:-d— date (newest first) -
/o:s— size
5. /b — bare format (names only)
dir /b
One name per line. No headers. Ideal for scripts:
dir /b /s *.txt > file-list.txt
Combine flags (real workflows)
Newest .dll files under this tree, names only:
dir /b /s /o:-d *.dll
Everything including hidden, sorted by name:
dir /a /o:n
Quick reference
| Goal | Command |
|---|---|
| Clean scan | dir /w |
| Include hidden | dir /a |
| Deep pattern search | dir /s *.ext |
| Script-friendly list | dir /b |
| Newest first | dir /o:-d |
Practice DIR hands-on
Reading flags helps. Typing them until they stick is better.
CMD Master is a free online interactive learning platform for the command line. Practice Windows CMD, PowerShell, and Bash in a live browser terminal with instant feedback — no install and no VM. Most lessons are free. For a structured Windows path that covers core commands like DIR, start the interactive Windows Command Prompt course.
Tip: run dir /? once in a real prompt to skim Microsoft’s full switch list, then drill the five above until they are muscle memory.
Further reading
- Microsoft Learn: DIR — complete official syntax and parameters
- CMD Master — learn CMD interactively — free browser practice for CMD, PowerShell, and Bash
Top comments (0)