CMD Options
CMD has several command-line options. Although you don't often need to use these options, you might want to be familiar with them. To start the command shell with alternative settings, you can type start cmd with additional parameters or run cmd from within a shortcut, batch file, and so on.
The syntax of the CMD command itself is as follows:
cmd [/a | /u] [/q] [/d] [/t:fg] [/e:on|off] [/f:on|off] [/v:on|off] [[/s] [/c | /k] [command]
You can give CMD a specific command line to execute, or you can start it without a command. In the latter case, it repeatedly prompts for commands.
The options are described here.The features noted with an asterisk are discussed in the following sections:
Options | Descriptions |
---|---|
/a | Causes standard output to use ANSI encoding. |
/u | Causes standard output to use Unicode encoding. |
/q | Turns the batch file echo default to off. |
/d | Disables execution of AutoRun commands defined in the Registry. Use this if a rogue program (or you) sets up a bad AutoRun entry. |
/t:bf | Sets the background (window) and foreground (text) colors for the window. For example, /t:80 specifies black text on a gray background. The color values are listed in Table below. |
/e | Enables or disables the command extensions. |
/f | Enables or disables the file and directory name completion feature. |
/v | Enables delayed environment variable expansion of !varname! |
/s | Modifies the treatment of quotation marks on the command line |
/c | Executes the command(s) in command and then quits. |
/k | Executes the command(s) in command and then reads further commands from the standard input until end of file or until the exit command is received. |
If used, the /c or /k option must appear immediately before the command string. Anything after /c or /k is treated as part of the command to be run, rather than an argument to CMD.
Several nonstandard command-line arguments are also recognized to maintain compatibility with batch files written for Windows NT 4.0:
Arguments | Description |
---|---|
/x | Same as /e:on. Enables command extensions. |
/y | Same as /e:off. Disables command extensions. |
/r | Same as /c. Executes command and quits. |
The color codes used with /t are listed in Table below.
Color Codes Used with /tValue | Color |
---|---|
0 | Black |
1 | Blue |
2 | Green |
3 | Aqua |
4 | Red |
5 | Purple |
6 | Yellow |
7 | White |
8 | Gray |
9 | Light Blue |
A | Light Green |
B | Light Aqua |
C | Light Red |
D | Light Purple |
E | Light Yellow |
F | Bright White |
In this tutorial:
- The CMD Command-Line
- CMD Versus COMMAND
- Running CMD
- Opening a Command Prompt Window with Administrator Privileges
- CMD Options
- Disabling Command Extensions
- Command-Line Processing
- Console Program Input and Output
- Using the Console Window
- I/O Redirection and Pipes
- Copy and Paste in Command Prompt Windows
- Command Editing and the History List
- Name Completion
- Enabling Directory Name Completion
- Multiple Commands on One Line
- Grouping Commands with Parentheses
- Arguments, Commas, and Quotes
- Escaping Special Characters
- Configuring the CMD Program
- The Search Path
- Changing the Path
- Predefined and Virtual Environment Variables
- Setting Default Environment Variables
- Built-in Commands
- Extended Commands
- Listing Files with the Dir Command
- Paginating Long Listings
- Printing Directory Listings
- Sorting Listings
- Locating Alternate File Streams
- Setting Variables with the Set Command
- Conditional Processing with the if Command
- Scanning for Files with the for Command
- Using the for Command's Variable
- Processing Directories
- Numerical for Loop
- Getting More Information