Microsoft DOS dir command

Updated: 05/22/2018 by Computer Hope

About dir

The dir command displays information about files and directories, and how much disk space is available. By default, it displays the name, size, and last modification time of every file in the current directory.

Availability

The dir command is an internal command available in the command line of all Microsoft operating systems.

Description

The dir command displays a list of files and subdirectories in a directory. With the /S option, it recurses subdirectories and lists their contents as well.

Options listed below may be preset in the DIRCMD environment variable. To override preset options, prefix any switch with - (hyphen), for example, "/-W".

Syntax

The syntax of the dir command has evolved somewhat over time. Select your operating system to jump to the information that applies to your version.

Syntax in Windows 10, 8, 7, Vista, XP, and 2000.

DIR [Drive:][Path][FileName] [/A[[:]Attributes]] [/B] [/C] [/D] [/L] [/N]
    [/O[[:]SortOrder]] [/P] [/Q] [/R] [/S] [/T[[:]TimeField]] [/W] [/X] [/4]
[Drive:][Path][FileName] Specifies the drive, directory, or files to list. Multiple filespecs are allowed, e.g., "*.txt *.exe".
/A:Attributes Displays only files with the specified file attributes. Attributes is a series of letters, each representing an attribute as shown below.

D : Directories.
R : Read-only files.
H : Hidden files.
A : Files marked ready for archiving.
S : System files.
I : Non-indexed files.
L : Reparse points.
- : Prefix meaning "not".

For example, the option "/A:R-A" would match only files whose attributes (/A:) are read-only (R) and not (-) ready to be archived (A).
/B Uses bare format (no heading information or summary, just the information itself).
/C Display the thousand separator in file sizes (e.g., a comma after every third digit), which is the default setting. Use /-C to disable the display of separator.
/D Same as wide (/W), but files are sorted by column, rather than by row.
/L Uses lowercase in the output.
/N "New long-list" format, which displays file names on the far right.
/O:SortOrder Sort the list of files by SortOrder, a series of letters representing sort criteria.

N : By name (alphabetic).
S : By size (smallest first).
E : By extension (alphabetic).
D : By date/time (oldest first).
G : Group directories first.
- : Prefix to reverse order.

For instance, an option of "/O:D" displays files oldest-to-newest, and "/O:-S" displays files biggest-to-smallest.
/P Pauses after each screenful of information.
/Q Display the owner of the file.
/R Display alternate data streams of the file.
/S Displays files recursively, traversing any subdirectories.
/T TimeField Specify the time field displayed and used for sorting. TimeField may be any of the following letters.

C : Creation time.
A : Last access time.
W : Last write time.

For instance, when you use the option "/T:C," the time listed is when the file was created.
/W Uses wide list format, displaying file/folder names only, with multiple names on every line.
/X Displays the short names generated for non-8dot3 file names. The format is that of /N ("new long-list" format, see above), with the short name inserted before the long name. If no short name is present, blanks are displayed in its place.
/4 Display years with four digits, e.g., 2018 instead of 18.

Syntax in Windows ME, 98, 95, 3.x, and MS-DOS.

DIR [Drive:][Path][FileName] [/P] [/W] [/A[[:]attributes]] [/O[[:]sortorder]] [/S]
    [/B] [/L] [/V]
[Drive:][Path][FileName] Specifies drive, directory, or files to list. Multiple filespecs are allowed, e.g., "*.txt *.exe".
/P Pauses after each screenful of information.
/W Uses wide list format.
/A[:Attributes] List only files with the specified file attributes. Attributes is a series of letters indicating.

D : Directories.
R : Read-only files.
H : Hidden files.
A : Files ready for archiving.
S : System files.
- : Prefix meaning "not".
/O[:SortOrder] List files in sorted order, indicated by SortOrder.

N : By name (alphabetic).
S : By size (smallest first).
E : By extension (alphabetic).
D : By date and time (earliest first).
G : Group directories first.
- : Prefix to reverse order.
A : By last access date (earliest first).
/S List files and directories recursively, traversing subdirectories.
/B Uses bare format (no heading information or summary).
/L Uses lowercase.
/V Verbose mode. Display extra information.

Examples

dir

Lists all files and directories in the current directory.

dir *.exe

Lists any file whose name has the file extension ".exe".

dir *.txt *.doc

List any files whose name has the file extension ".txt" or ".doc".

dir /a:d

Lists only directories.

dir /a:r

List only files with the read-only attribute.

dir /s

Recursively lists files and directories in the directory, and in any subdirectories. For instance, if your current directory is the root directory "C:\>," this command this will list every file and directory on the C: drive.

dir /p

Pause after each screenful of output. Use this option if the information is scrolling past the screen before you can read it. You'll be prompted to press any key before listing continues past the current screen.

dir /w

Lists multiple file names on every line, producing "wide" output, which displays more file names at once. However, other information such as file size is omitted.

dir /s /w /p

Recursively lists all files and directories in the current directory and any subdirectories, in wide format, pausing after each screen of output.

dir /s /w /p "C:\Program Files"

Same as the above command, but lists everything in C:\Program Files, instead of the current directory. Because the directory name contains a space, it is enclosed in double-quotes, to prevent it from being interpreted is as two separate options.

dir /o:n

Lists files and directories in the current directory in alphabetical order. This example is the same as just running dir because files and directories are listed in alphabetical order by default.

dir /o:-n

Lists files in reverse alphabetical order.

dir /s /q /a:sh /p C:\Windows

Lists any files and directories in C:\Windows, and any of its subdirectories (/s), which have both the "hidden" and "system" file attributes (/a:sh). Also, lists the owner of the file (/q), and pauses after each screen of output (/p).

dir \ /s | find "i" | more

The above command uses vertical bars to pipe the output from dir to the command find, and then to the command more. The result is a list of all files and directories in the root directory of the current drive (\), with extra information. Namely, find will also display the number of files in each directory, and the amount of space occupied by each.

dir > myfile.txt

Runs the dir command, but redirects the output to the file myfile.txt, instead of displaying it on the screen. Here, the dir command has no options, but redirection will work with any command you specify, so this will also work:

dir /s /a:hs /q C:\Windows > myfile.txt

To view the contents of the file, you can use the type command:

type myfile.txt

If the file is very long, you can pipe type to more, so it pauses after each screen:

type myfile.txt | more

Additional information