dirDIR vs DIR /B: bare list vs full columns in CMD
Compare dir and dir /b in Windows CMD: when to use bare format, FOR /F parsing, scripts, sorting /o, attributes /a, and pitfalls with spaces.
dir lists files and subdirectories with headers, columns for date/time, size, and summary footers. dir /b (“bare”) prints only names—one per line—making it ideal for piping into other commands, FOR /F, or quick filename harvesting without decorative noise. Both answer the classic question: which Windows command shows directory contents? — dir (not ls, though PowerShell aliases exist).
Automation engineers standardize on /b for predictable tokenization; humans prefer default layout for visual scanning. Mixing attributes /a, order /o, and recursion /s with /b unlocks advanced inventory scripts supporting security scanning, build artifact verification, and storage analytics.
This guide contrasts outputs, supplies syntax tables, ten examples (including hidden file sorts cross-linking hidden files sorted), troubleshooting garbled parsing from summary lines, FAQ, quick reference, internal links DIR, TREE overview, simulator CTA.
Output Differences
Default dir shows volume label (sometimes), header line, per-file rows, free bytes summary.
dir /b lists:
file1.txt
SubFolder
No metadata columns—faster, easier to parse.
Syntax Building Blocks
DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N] ...
Commonly combined:
| Combo | Effect |
|---|---|
dir /b | Names only |
dir /a:h /b | Hidden names only |
dir /s /b | Recursive names full path |
dir /o:s | Sort size ascending (no /b) |
Note: /o sorts apply to standard output more visually; with /b still sorts names generally—validate script assumptions on your build.
Examples
- Build pipeline listing
dist\*.zipbare for upload script iteration. - Malware triage enumerating
%TEMP%anomalies feeding hash script sequentially. - Counting files
dir /b | find /c /v ""classic pattern (care empty folder edge). - FOR /F ingest
for /f "delims=" %F in ('dir /b *.log') do echo Processing %F. - Long path combine
\\?\prefix strategies consistent with operations guides. - Git clean preview mental model analogous though git owns logic—comparison teaching point.
- Music library scripting playlist generation gathering mp3 filenames only.
- Photo ingest DSLR DCIM subdirectory bare listing feeding exiftool loops external cross mention.
- Disk space dashboards pairing
/s /bwith external size query since bare suppresses sizes—requires different tooling note honesty. - Education: conceptual MCQ distinguishes
dirlisting vstreehierarchical ascii art companion TREE.
Transparency: /b removes size columns—for size sorting visible use standard dir /o:s presentation or [dir hidden sort article](/blog/dir-hidden-files-sort-by-size).
Recursive inventory caution
dir /s /b > listing.txt
Large trees explode file size—plan disk accordingly.
Use Cases Expanded
MSP patch staging enumerations; motion picture render farm output watchers; genomic pipeline massive cluster file fan-out watchers; ecommerce image CDN batch sync prelude manifest generation; virtualization template dedupe listing; archival legal discovery preliminary file Universe enumerations sanitized; ICS historian exports validation; SaaS onboarding migration file transfer calculators; Observability flaky integration test artifact sweeper scripting; Charity nonprofit donor receipt mail merge prepping structured lists anonymized illustrative only.
Troubleshooting
Trailing summary lines polluted piped data when /b omitted accidentally—classic bug.
Unicode names—ensure console code page chcp 65001 when needed.
Junction loops—possible infinite recursion careless custom walkers—not dir's fault but operator awareness vital.
Tips
Prefer dir /b 2>nul suppress errors listing optional globs probing existence softly.
Combine /a-d to list files only excluding directories—helpful cleaning scripts.
Document difference between wildcard in current directory vs explicit path argument reducing relative path ambiguous bugs.
Related Commands
- DIR master guide
- TREE
- FORFILES time-based sweeps
Frequently Asked Questions
Does /b show system files?
Only if /a includes them—default /b obeys typical visibility unless attributes flags expand set.
PowerShell Get-ChildItem bare?
Different cmdlet—Name property projection analogous conceptually.
Does dir equal ls in CMD?
ls not native cmd.exe—PowerShell alias—avoid teaching confusion in pure CMD classes.
Quick Reference
dir /b
dir /a:-d /b
dir /s /b C:\Data
Interactive practice: simulator, reference: commands.
Summary
Choosing between dir and dir /b is choosing between human-friendly listings and machine-friendly tokens. Combine /b with attribute and recursion flags deliberately, mind summary-line pollution, measure performance on huge trees, and align scripts with parser realities so automation stays boringly reliable—the best kind of enterprise scripting outcome reducing pager noise volume quarter over quarter objectively measurable.