Peek Inside Like a Pro: The dir Command Explained

When you’re working in Windows Command Prompt, one of the first things you’ll probably type is:

cmd
dir

And boom — a list of files and folders appears. It’s simple. It’s fast. It’s the CLI version of File Explorer. But did you know dir has a bunch of powerful switches that can filter, sort, and format that list to your exact needs?

Let’s go beyond the basics and explore what dir can really do.

What Is dir?

The dir command is used to list files and folders in the current directory (or a specified one). It’s short for “directory”, and it’s been a staple of Windows (and DOS) since forever.


Basic Syntax

cmd
dir [path] [options]

Examples:

cmd
dir
dir C:\Windows
dir *.txt

Common Switches and What They Do

Here’s a breakdown of the most useful dir switches (there are quite a few!):

/P – Pause after each screenful

cmd
dir /P

Useful when you’re in a folder with tons of files and don’t want everything to scroll past at warp speed.

/W – Wide format

cmd
dir /W

Displays filenames in columns. Great for a quick overview without details like size and dates.

/B – Bare format (just filenames)

cmd
dir /B

Perfect for scripting. No headers, sizes, or dates — just a clean list.

cmd
dir *.txt /B

Example output:

notes.txt
todo.txt
summary.txt

/S – Include all subdirectories

cmd
dir /S

Lists everything under the current directory — including files in all subfolders. Combine with /B for full paths only:

cmd
dir /S /B *.log

/A – Show files with specific attributes

cmd
dir /A:H

Lists hidden files. Other options include:

  • H = Hidden
  • S = System
  • D = Directories
  • R = Read-only
  • A = Archive

You can combine them:

cmd
dir /A:HS

/O – Sort output

cmd
dir /O:N

Sorts by name. Other sort options include:

  • N = Name
  • S = Size
  • D = Date
  • E = Extension
  • G = Group directories first

📦 Example: sort files by size (largest first)

cmd
dir /O:-S

/T – Choose which timestamp to show

cmd
dir /T:C

Use with /T: to display:

  • C = Creation time
  • A = Last Accessed
  • W = Last Written (default)

💡 Combined Example

Let’s say you want a list of all .log files, including subfolders, sorted by size, with full paths and no extra info.

cmd
dir *.log /S /B /O:-S

That one-liner is perfect for log cleanup scripts or report generators.


Bonus: Find Junctions and Symlinks

Want to spot symbolic links or junctions?

cmd
dir /AL

This shows reparse points — a fancy name for things like symbolic links.


📜 Cheat Sheet Table

CommandWhat It Does
dirList contents of current folder
dir /WWide view (filenames only)
dir /PPause after screenful of output
dir /SRecursively list all files
dir /BBare format (filenames only)
dir /A:HShow hidden files
dir /O:NSort by name
dir /O:-SSort by size (largest first)
dir /ALShow symlinks and junctions

Final Thoughts

The dir command may seem basic, but with the right switches, it becomes a powerful tool for file audits, scripting, or just finding that lost .ini file buried 30 folders deep.

So next time you’re inside cmd.exe, ditch the mouse and let dir do the digging.

Want to take it further? In an upcoming post, we’ll compare dir to PowerShell’s Get-ChildItem — and show how to upgrade from basic output to full-blown file automation.

Leave a Comment