System command

dir command

List files and subdirectories, with filters, sorting and output-format switches.

Availability: Microsoft Learn command reference spanning Windows client and Windows Server releases; some entries are legacy, role-specific, optional-feature or interactive subcommands.中文

Documented syntax

dir [<drive>:][<path>][<filename>] [...] [/p] [/q] [/w] [/d] [/a[[:]<attributes>]][/o[[:]<sortorder>]] [/t[[:]<timefield>]] [/s] [/b] [/l] [/n] [/x] [/c] [/4] [/r]

The linked Microsoft Learn article is the upstream authority. Availability may depend on Windows release, role, optional feature or interactive tool context.

Examples

List files and folders in the current directory.

dir

Show all items, sort by date in reverse order and pause between screens.

dir /a /o:-d /p

List matching log-file paths under C: and its subdirectories.

dir /s /b C:\*.log

List matching files recursively without listing directories.

dir /s /b /a:-d *.txt

Parameters, options and clauses

Option / clauseDescription
[<drive>:][<path>][<filename>]Select a drive, directory or matching file names.
/pPause after each screen of output.
/qShow file ownership information.
/w /dUse wide output; /d sorts the wide listing by columns.
/a[:<attributes>]Filter by directory, hidden, system, reparse-point, read-only, archive or non-indexed attributes; prefix - to exclude an attribute.
/o[:<sortorder>]Sort by name, extension, directory-first, size or date/time; prefix - to reverse a key.
/t[:c|a|w]Select creation, last-access or last-write time.
/sList matching items in the current directory and all subdirectories.
/bUse a bare listing without summary information.
/l /nUse lowercase names or long-list format.
/xShow short names generated for non-8.3 file names.
/c /-cShow or suppress thousands separators in file sizes.
/4Display years with four digits.
/rDisplay alternate data streams.
/?Display command help at the prompt.
<timefield>Microsoft documents this argument or subcommand; check the linked reference for its required format and context.
Safety note

Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.

Official reference ↗Back to directory