DOS (Disk Operating System) is an interface that a system administrator can use to perform tasks and configure the system by typing text commands. The interface is referred to as the command line. To run DOS commands you need to open a command window. To open a command window select Start | All Programs | Accessories and click on Command Prompt.
A command window is a window that displays the DOS prompt. The DOS prompt is the location in the command window where you type command text. There are many commands available with the DOS command line interface, most of them feature switches, and wild cards which make them very powerful.
dir is a very common DOS command. The dir command returns a list of all the folders and files in the path listed in the DOS Prompt. Type dir at the blinking insertion cursor and press the keyboard [Enter] key. A list of all the folders and files in the path listed should appear in the command window.
c:\myfiles dir Volume in drive C has no label. Volume Serial Number is 3C7A-A692 Directory of C:\myfiles 06/08/2009 10:00 AM. 06/08/2009 10:00 AM .. 08/20/2008 03:11 PM 2,352 cat story.txt 02/02/2006 11:33 AM 14,998 charcodes.txt 12/31/2007 01:42 PM 1,036 create your own.txt 06/06/2008 09:15 AM 2,230 deathid.txt 08/07/2008 08:34 AM 19,226 diet.txt 12/12/2008 09:09 AM 448 ebayServices.txt 09/30/2008 08:10 AM 2,761 greeting cards.txt 02/17/2006 09:45 AM 669 micromanage.txt 12/12/2007 12:29 PM 159 negotiating_ploys.txt 03/18/2008 11:00 AM 11,854 pharmaceuticals.txt 03/24/2008 08:00 AM 1,578 Photo Radar.txt 06/21/2008 04:25 PM 4,506 SS benefits.txt 12 File(s) 61,817 bytes 2 Dir(s) 198,174,113,792 bytes free
Dos Command Switches
Switches let you control any options available with a DOS command. A switch is a character prefaced with a forward slash. A switch must be separated from the command and from other switches by a space. Shown below is use of the dir command with the /p switch, which causes the list of folders and files to be paged.
c:\myfiles dir /p Volume in drive C has no label. Volume Serial Number is 3C7A-A692 Directory of C:\myfiles 06/08/2009 10:00 AM. 06/08/2009 10:00 AM .. 08/20/2008 03:11 PM 2,352 cat story.txt 02/02/2006 11:33 AM 14,998 charcodes.txt 12/31/2007 01:42 PM 1,036 create your own.txt 06/06/2008 09:15 AM 2,230 deathid.txt Press any key to continue . . . _
This switch could be very useful if, for example, you wanted to get a list of all the folders and files in the c:\Windows\System32 folder or any folder that contains a large number of folders and / or files.
Some switches themselves have options. In that case the switch and the option is separated by a colon. Shown below is use of the dir command with the /o:d switch, which causes the list of folders and files to be ordered by date.
c:\myfiles dir /o:d Volume in drive C has no label. Volume Serial Number is 3C7A-A692 Directory of C:\myfiles 02/02/2006 11:33 AM 14,998 charcodes.txt 02/17/2006 09:45 AM 669 micromanage.txt 12/12/2007 12:29 PM 159 negotiating_ploys.txt 12/31/2007 01:42 PM 1,036 create your own.txt 03/18/2008 11:00 AM 11,854 pharmaceuticals.txt 03/24/2008 08:00 AM 1,578 Photo Radar.txt 06/06/2008 09:15 AM 2,230 deathid.txt 06/21/2008 04:25 PM 4,506 SS benefits.txt 08/07/2008 08:34 AM 19,226 diet.txt 08/20/2008 03:11 PM 2,352 cat story.txt 09/30/2008 08:10 AM 2,761 greeting cards.txt 12/12/2008 09:09 AM 448 ebayServices.txt 06/08/2009 10:27 AM.. 06/08/2009 10:27 AM . 12 File(s) 61,817 bytes 2 Dir(s) 198,174,113,792 bytes free
The /? switch, used with any DOS command, displays a description of the command, a useage chart, a list of all the commands options, and a description of each option. Shown below is the information returned when the /? switch is used with the dir command.
Displays a list of files and subdirectories in a directory. 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 drive, directory, and/or files to list. /A Displays files with specified attributes. attributes D Directories R Read-only files H Hidden files A Files ready for archiving S System files I Not content indexed files L Reparse Points - Prefix meaning not /B Uses bare format (no heading information or summary). /C Display the thousand separator in file sizes. This is the default. Use /-C to disable display of separator. /D Same as wide but files are list sorted by column. /L Uses lowercase. /N New long list format where filenames are on the far right. /O List by files in sorted order. sortorder 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 /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 in specified directory and all subdirectories. /T Controls which time field displayed or used for sorting timefield C Creation A Last Access W Last Written /W Uses wide list format. /X This displays the short names generated for non-8dot3 file names. The format is that of /N with the short name inserted before the long name. If no short name is present, blanks are displayed in its place. /4 Displays four-digit years Switches may be preset in the DIRCMD environment variable. Override preset switches by prefixing any switch with - (hyphen)--for example, /-W.
DOS Command Wild Cards
Wildcards are characters that are used to represent unknown characters in file names. The wildcard character ? represents a single unknown character. The The wildcard character * represents multiple unknown characters. Shown below is the results of using the wildcard * used with the dir command.
C:\myfiles>dir *.* Volume in drive C has no label. Volume Serial Number is 3C7A-A692 Directory of C:\myfiles 06/08/2009 11:37 AM. 06/08/2009 11:37 AM .. 08/20/2008 03:11 PM 2,352 cat story.txt 02/02/2006 11:33 AM 14,998 charcodes.txt 09/25/2007 09:31 AM 6,168 Chinch_Bug.gif 12/31/2007 01:42 PM 1,036 create your own.txt 06/06/2008 09:15 AM 2,230 deathid.txt 08/07/2008 08:34 AM 19,226 diet.txt 12/12/2008 09:09 AM 448 ebayServices.txt 09/25/2007 06:14 AM 8,350 Grasshopper_a.gif 09/25/2007 06:41 AM 8,533 Grasshopper_b.gif 09/25/2007 06:57 AM 8,746 Grasshopper_c.gif 09/30/2008 08:10 AM 2,761 greeting cards.txt 02/17/2006 09:45 AM 669 micromanage.txt 03/18/2008 11:00 AM 11,854 pharmaceuticals.txt 03/24/2008 08:00 AM 1,578 Photo Radar.txt 09/20/2007 10:32 AM 5,278 Spanish_Fly.gif 09/20/2007 09:40 AM 3,179 Squash_Beetle.gif 09/20/2007 09:33 AM 4,467 Squash_Bug.gif 09/20/2007 09:28 AM 4,425 Squash_Ladybird.gif 09/19/2007 11:59 AM 6,802 Water_Beetle.gif 19 File(s) 113,100 bytes 2 Dir(s) 198,174,478,336 bytes free
As you can see you get the same results as if you used the dir command with no wildcards. The folder contains both text files (.txt) and image files (.gif).
If you wanted the dir command to list only the image files you could use the * wildcard with the .gif file extension (*.gif). The results of this is shown below.
C:\myfiles>dir *.gif Volume in drive C has no label. Volume Serial Number is 3C7A-A692 Directory of C:\myfiles 09/25/2007 09:31 AM 6,168 Chinch_Bug.gif 09/25/2007 06:14 AM 8,350 Grasshopper_a.gif 09/25/2007 06:41 AM 8,533 Grasshopper_b.gif 09/25/2007 06:57 AM 8,746 Grasshopper_c.gif 09/20/2007 10:32 AM 5,278 Spanish_Fly.gif 09/20/2007 09:40 AM 3,179 Squash_Beetle.gif 09/20/2007 09:33 AM 4,467 Squash_Bug.gif 09/20/2007 09:28 AM 4,425 Squash_Ladybird.gif 09/19/2007 11:59 AM 6,802 Water_Beetle.gif 9 File(s) 55,948 bytes 0 Dir(s) 198,175,821,824 bytes free
If you wanted the dir command to list only the image files with the character string Squash in the name, you could use the * wildcard this way: Squash*.gif. The results of this is shown below.
C:\myfiles>dir Squash*.gif Volume in drive C has no label. Volume Serial Number is 3C7A-A692 Directory of C:\myfiles 09/20/2007 09:40 AM 3,179 Squash_Beetle.gif 09/20/2007 09:33 AM 4,467 Squash_Bug.gif 09/20/2007 09:28 AM 4,425 Squash_Ladybird.gif 3 File(s) 12,071 bytes 0 Dir(s) 198,175,625,216 bytes free
If you wanted the dir command to list only the image files containing the character string Grasshopper_ followed by a single character in their name, you could use the ? wildcard this way: Grasshopper_?.gif. The results of this is shown below.
C:\myfiles>dir Grasshopper_?.gif Volume in drive C has no label. Volume Serial Number is 3C7A-A692 Directory of C:\myfiles 09/25/2007 06:14 AM 8,350 Grasshopper_a.gif 09/25/2007 06:41 AM 8,533 Grasshopper_b.gif 09/25/2007 06:57 AM 8,746 Grasshopper_c.gif 3 File(s) 25,629 bytes 0 Dir(s) 198,176,411,648 bytes free
The ? wildcard represents a single unknown character. If you wanted the dir command to list only the files containing the character string _Bug.gif preceded by 6 unknown characters, you would use 6 ? wildcards this way: ??????_Bug.gif. The results of this is shown below.
C:\myfiles>dir ??????_Bug.gif Volume in drive C has no label. Volume Serial Number is 3C7A-A692 Directory of C:\myfiles 09/25/2007 09:31 AM 6,168 Chinch_Bug.gif 09/20/2007 09:33 AM 4,467 Squash_Bug.gif 2 File(s) 10,635 bytes 0 Dir(s) 198,174,900,224 bytes free
Wildcards can be used with any DOS command that works with file names, for example the delete and copy commands. In this article you learned how powerful DOS commands can be when used with switches and wild cards.
More Windows Administration Information:
• Font Basics
• Choosing a Tape Drive
• A Brief Introduction to 3D Printing
• Disable Automatic Wireless Configuration in Windows 7
• The Windows 7 Backup and Restore Utility
• Hands-On Microsoft Windows Server 2008 Administration
• How to Share a Folder in Windows 7
• What is Hyper-V in Windows Server 2019?
• Restrict Web Browsing With Internet Explorer
• How to Manually Register DLL in Microsoft Windows