DOS Commands :: dir
dirUse the dir command to output a listing of the contents of the current directory. Information about the files and subdirectories of the current directory will be displayed.
dir directory
By specifying a directory, the contents of that directory is displayed. For example,
dir *.txt
Displays a listing of all the .txt files located in the current (or specified) directory.
dir my*
Displays a listing of all files that start with the pattern you specify; in this example, "my".
There are a few options you can use with the dir command. See
The following examples demonstrate some of the more useful options:
dir /p
Pause the directory listing after every screenful. To continue the listing, press any key (e.g.: spacebar or Enter key).
dir /w
Wide directory listing.
dir /b
Displays a directory listing showing just the filenames without header information or file size/date. This bare format is useful when you just want the actual filenames and you're going to do some sort of further processing. For example
dir /o:gne
Displays a directory listing that is sorted. You specify the sort order by one or more letter after the /o: part. The most useful sort order is gne which puts all the subdirectories before files (g), and sorts by name (n), and then by filename ending (e). Tip: You can set the sort order (lasts until you close the DOS window) by typing a set command:
dir /o:s
Displays a directory listing that is sorted by size (smallest to largest). To reverse the sort order (largest size to smallest size), instead use:
dir /s
Displays the contents of the current directory (or specified directory) as well as the contents of all subdirectories and their subdirectories too. Since the output can be very long, especially if you have subdirectories inside subdirectories, you probably should also use the /p option to pause output. If you forget to do, you'll probably see the output zipping by on your screen; in that case, press
dir /s *.txt
Displays a listing of all .txt files located in the current directory and in all subdirectories.
dir /s mystuff.txt
Displays a listing of all instances of a file named mystuff.txt located in the current directory and in all subdirectories. Useful when you know the name of a file but don't recall which subdirectory it is located in. You can think of this command as the equivalent of the Windows Search Companion (accessible by pressing F3 when viewing a Windows folder).
dir /ah
Displays a listing of hidden files (if any) that are located in the directory. Tip: Use the attrib command to change the hidden attribute of a file.
Note: You can type more then one option at the same time. For example,