command/cmd (MS-DOS 的命令解释器)

嚯嚯 发表于 2020-06-29 15:24
浏览次数:
在手机上阅读

command.com(在Windows的更高版本中为CMD)是MS-DOS 的命令解释器,并且是Microsoft操作系统正常运行所必需的。没有command.com,运行Microsoft操作系统的计算机将无法启动。 当运行Windows NT,2000,XP,Vista,7、8和10时,有两个版本的命令解释器:command.com和cmd.exe。Cmd提供了比command.com 更多的环境变量。但是,如果您尝试运行使用command.com的MS-DOS实用工具,我们建议您这样做。要使用command.com,请单击“开始”,“运行”,然后键入command。

查看英文版

目录

1 command/cmd 运行系统环境

2 command 语法

3 command 示例

command/cmd 运行系统环境

Windows 95

Windows 98

Windows xp

Windows vista

Windows 2000

Windows 7

Windows 8

Windows 10

Windows NT

Windows ME

All Versions of MS-DOS

command 语法

Windows 2000,XP,Vista,7、8和10“ cmd”语法

启动Windows 2000或Windows XP命令解释器的新实例。

>CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF] [[/S] [/C | /K] string]
/C 执行由字符串指定的命令,然后终止。
/K 执行由字符串指定的命令,但保留。
/S 修改/ C或/ K之后的字符串处理(请参见下文)。
/Q 关闭回显
/D 从注册表中禁用自动运行命令的执行(请参见下文)。
/A 使内部命令到管道或文件的输出为ANSI。
/U 使内部命令到管道或文件的输出为Unicode。
/T:fg 设置前景色/背景色(有关更多信息,请参见COLOR /?)。
/E:ON 启用命令扩展名(请参见下文)。
/E:OFF 禁用命令扩展名(请参见下文)。
/F:ON 启用文件和目录名称完成字符(请参见下文)。
/F:OFF 禁用文件和目录名称完成字符(请参见下文)。
/V:ON 使用c作为分隔符启用延迟的环境变量扩展。例如,/ V:ON将允许!var!。在执行时扩展变量var。var 语法在输入时扩展变量,而在FOR循环中则完全不同。
/V:OFF 禁用延迟的环境扩展。

请注意,如果字符串用引号引起来,则接受用命令分隔符“ &&”分隔的多个命令。另外,出于兼容性原因,/ X与/ E:ON相同,/ Y与/ E:OFF相同,/ R与/ C相同。任何其他开关都将被忽略。

如果指定了/ C或/ K,则将切换后的命令行其余部分作为命令行处理,其中以下逻辑用于处理引号(“)字符:

1. 如果满足以下所有条件,则保留命令行上的引号字符:

  • 不带 /S 开关
  • 正好两个引号字符
  • 两个引号字符之间没有特殊字符,其中特殊字符是以下之一:&<>()@ ^ | 字符。
  • 两个引号字符之间有一个或多个空格字符
  • 两个引号字符之间的字符串是可执行文件的名称。

2. 否则,旧习惯是查看第一个字符是否为引号字符。如果是这样,请删除开头的字符并删除命令行上的最后一个引号字符,并保留最后一个引号字符之后的所有文本。

如果未在命令行上指定/ D,则在CMD.EXE启动时,它将查找以下REG_SZ / REG_EXPAND_SZ注册表变量,并且如果存在一个或两个,则将首先执行它们。

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun

HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun

默认情况下,命令扩展是启用的。您还可以使用/ E:OFF开关禁用特定调用的扩展名。您可以通过使用REGEDT32.EXE在注册表中将以下两个REG_DWORD值之一或全部设置为0x10x0,来启用或禁用CMD.EXE的所有调用的扩展名:

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\EnableExtensions

HKEY_CURRENT_USER\Software\Microsoft\Command Processor\EnableExtensions

用户特定设置优先于机器设置。命令行开关优先于注册表设置。

命令扩展名涉及对以下命令的更改或添加。

  • DEL or ERASE
  • COLOR
  • CD or CHDIR
  • MD or MKDIR
  • PROMPT
  • PUSHD
  • POPD
  • SET
  • SETLOCAL
  • ENDLOCAL
  • IF
  • FOR
  • CALL
  • SHIFT
  • GOTO
  • START (同时包括对外部命令调用所做的更改)。
  • ASSOC
  • FType

要获取特定的详细信息,请键入/?查看详细信息。其中是要指定其名称的命令的名称。

默认情况下不启用延迟的环境变量扩展。您可以使用/ V:ON或/ V:OFF开关来为CMD.EXE的特定调用启用或禁用延迟的环境变量扩展。若要启用或禁用对CMD.EXE的所有调用的完成,请使用REGEDT32.EXE在注册表中将以下两个REG_DWORD值之一或全部设置为0x10x0

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\DelayedExpansion

HKEY_CURRENT_USER\Software\Microsoft\Command Processor\DelayedExpansion

用户特定设置优先于机器设置。命令行开关优先于注册表设置。

如果启用了延迟的环境变量扩展,则感叹号可以在执行时替换环境变量的值。

默认情况下不启用文件和目录名称完成。您可以使用/ F:ON或/ F:OFF开关来启用或禁用CMD.EXE的特定调用的文件名完成。若要为计算机或用户登录会话上的CMD.EXE的所有调用启用或禁用完成,请使用REGEDT32.EXE在注册表中设置以下两个REG_DWORD值之一或全部:

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\CompletionChar
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\PathCompletionChar

HKEY_CURRENT_USER\Software\Microsoft\Command Processor\CompletionChar
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\PathCompletionChar

具有用于特定功能的控制字符的十六进制值(例如0x4为Ctrl-D,0x6为Ctrl-F)。用户特定的设置优先于机器设置。命令行开关优先于注册表设置。

如果使用/ F:ON开关启用了完成功能,则使用的两个控制字符是Ctrl-D(用于完成目录名)和Ctrl-F(用于完成文件名)。要在注册表中禁用特定的完成字符,请使用空格(0x20)值,因为它不是有效的控制字符。

如果键入两个控制字符中的一个,完成会被调用。完成功能将路径字符串带到光标的左边,如果没有通配符,将通配符附加到左边,并建立相符的路径列表。然后,显示第一个相符的路径。如果没有相符的路径,则发出嘟嘟声,不影响显示。之后,重复按同一个控制字符会循环显示相符路径的列表。将 Shift键跟控制字符同时按下,会倒着显示列表。如果对该行进行了任何编辑,并再次按下控制字符,保存的相符路径的列表会被丢弃,新的会被生成。如果在文件和目录名完成之间切换,会发生同样现象。两个控制字符之间的唯一区别是文件完成字符符合文件和目录名,而目录完成字符只符合目录名。如果文件完成被用于内置式目录命令(CD、MD 或 RD),就会使用目录完成。

补全代码通过在匹配路径周围加上引号来正确处理包含空格或其他特殊字符的文件名。另外,如果您进行备份,然后从一行中调用完成,则在调用完成点时光标右侧的文本也会被丢弃。

需要引号的特殊字符是:

&()[]{}^=;!'+,`~

Windows早期的“命令”语法

启动Windows命令解释器的新副本。

>COMMAND [[drive:] path] [device] [/E:nnnnn] [/L:nnnn] [/U:nnn] [/P] [/MSG] [/LOW] [/Y [/C|K] command]
[drive:]path 指定包含COMMAND.COM的目录。
device 指定用于命令输入和输出的设备。
/E:nnnnn 将初始环境大小设置为nnnnn字节。(nnnnn应该介于256和32,768之间)。
/L:nnnn 指定内部缓冲区的长度(也需要/ P)。(nnnn应介于128和1,024之间)。
/U:nnn 指定输入缓冲区的长度(也需要/ P)。(nnn应该在128和255之间)。
/P 使新的命令解释器永久存在(无法退出)。
/MSG 将所有错误消息存储在内存中(也需要/ P)。
/LOW 强制COMMAND将其常驻数据保留在低内存中。
/Y 逐步执行/ C或/ K指定的批处理程序。仅在MS-DOS 6.x及更高版本中可用。
/C command 执行指定的命令并返回
/K command 执行指定的命令并继续运行。
/Z 显示执行的每个命令的错误级别。仅在MS-DOS 7.x及更高版本中可用。

Windows 2000, XP, Vista, 7, 8, and 10 "cmd" syntax

Starts a new instance of the Windows 2000 or Windows XP command interpreter.

>CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF] [[/S] [/C | /K] string]
/C Carries out the command specified by string and then terminates.
/K Carries out the command specified by string but remains.
/S Modifies the treatment of string after /C or /K (see below).
/Q Turns echo off.
/D Disable execution of AutoRun commands from registry (see below).
/A Causes the output of internal commands to a pipe or file to be ANSI.
/U Causes the output of internal commands to a pipe or file to be Unicode.
/T:fg Sets the foreground/background colors (see COLOR /? for more info).
/E:ON Enable command extensions (see below).
/E:OFF Disable command extensions (see below).
/F:ON Enable file and directory name completion characters (see below).
/F:OFF Disable file and directory name completion characters (see below).
/V:ON Enable delayed environment variable expansion using c as the delimiter. For example, /V:ON would allow !var! to expand the variable var at execution time. The var syntax expands variables at input time, which is quite a different thing when inside of a FOR loop.
/V:OFF Disable delayed environment expansion.

Note that multiple commands separated by the command separator '&&' are accepted for the string if it's surrounded by quotes. Also, for compatibility reasons, /X is the same as /E:ON, /Y is the same as /E:OFF and /R is the same as /C. Any other switches are ignored.

If /C or /K is specified, the remainder of the command line after the switch is processed as a command line, where the following logic is used to process quote (") characters:

1. If all the following conditions are met, then quote characters on the command line are preserved:

  • No /S switch.
  • Exactly two quote characters.
  • No special characters between the two quote characters, where special is one of: &<>()@^| characters.
  • There are one or more whitespace characters between the two quote characters.
  • The string between the two quote characters is the name of an executable file.

2. Otherwise, old behavior is to see if the first character is a quote character. If so, strip the leading character and remove the last quote character on the command line, preserving any text after the last quote character.

If /D was NOT specified on the command line, then when CMD.EXE starts, it looks for the following REG_SZ/REG_EXPAND_SZ registry variables, and if either or both are present, they are executed first.

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun

or

HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun

Command Extensions are enabled by default. You may also disable extensions for a particular invocation by using the /E:OFF switch. You can enable or disable extensions for all invocations of CMD.EXE by setting either or both of the following REG_DWORD values to either 0x1 or 0x0 in the registry using REGEDT32.EXE:

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\EnableExtensions

or

HKEY_CURRENT_USER\Software\Microsoft\Command Processor\EnableExtensions

The user-specific setting takes precedence over the machine setting. The command line switches take precedence over the registry settings.

The command extensions involve changes or additions to the following commands.

  • DEL or ERASE
  • COLOR
  • CD or CHDIR
  • MD or MKDIR
  • PROMPT
  • PUSHD
  • POPD
  • SET
  • SETLOCAL
  • ENDLOCAL
  • IF
  • FOR
  • CALL
  • SHIFT
  • GOTO
  • START (also includes changes to external command invocation).
  • ASSOC
  • FType

To get specific details, type/? to view the specifics. Whereis the name of the command you want specifics on.

Delayed environment variable expansion is NOT enabled by default. You can enable or disable delayed environment variable expansion for a particular invocation of CMD.EXE with the /V:ON or /V:OFF switch. To enable or disable completion for all invocations of CMD.EXE set either or both of the following REG_DWORD values to either 0x1 or 0x0 in the registry using REGEDT32.EXE:

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\DelayedExpansion

or

HKEY_CURRENT_USER\Software\Microsoft\Command Processor\DelayedExpansion

The user-specific setting takes precedence over the machine setting. The command line switches take precedence over the registry settings.

If delayed environment variable expansion is enabled, then the exclamation character can substitute the value of an environment variable at execution time.

File and directory name completion is NOT enabled by default. You can enable or disable file name completion for a particular invocation of CMD.EXE with the /F:ON or /F:OFF switch. To enable or disable completion for all invocations of CMD.EXE on a machine or user logon session set either or both of the following REG_DWORD values in the registry using REGEDT32.EXE:

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\CompletionChar
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\PathCompletionChar

or

HKEY_CURRENT_USER\Software\Microsoft\Command Processor\CompletionChar
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\PathCompletionChar

with the hex value of a control character to use for a particular function (e.g., 0x4 is Ctrl-D and 0x6 is Ctrl-F). The user-specific settings take precedence over the machine settings. The command line switches take precedence over the registry settings.

If completion is enabled with the /F:ON switch, the two control characters used are Ctrl-D for directory name completion and Ctrl-F for file name completion. To disable a particular completion character in the registry, use the value for space (0x20) as it is not a valid control character.

Completion is invoked when you type either of the two control characters. The completion function appends a wildcard character to the left of the cursor if none is present and builds up a list of paths that match. It then displays the first matching path. If no paths match, it beeps and leaves the display alone. After that, repeated pressing of the same control character will cycle through the list of matching paths. Pressing the Shift key with the control character moves through the list backwards. If you edit the line in any way and press the control character again, the saved list of matching paths is discarded and a new one generated. The same occurs if you switch between file and directory name completion. The difference between the two control characters is the file completion character matches both file and directory names, while the directory completion character only matches directory names. If file completion is used on any of the built-in directory commands (CD, MD or RD) then directory completion is assumed.

The completion code deals correctly with file names that contain spaces or other special characters by placing quotes around the matching path. Also, if you back up, then invoke completion from within a line, the text to the right of the cursor at the point completion was invoked is discarded.

The special characters that require quotes are:

&()[]{}^=;!'+,`~

Early Windows "command" syntax

Starts a new copy of the Windows command interpreter.

>COMMAND [[drive:] path] [device] [/E:nnnnn] [/L:nnnn] [/U:nnn] [/P] [/MSG] [/LOW] [/Y [/C|K] command]
[drive:]path Specifies the directory containing COMMAND.COM.
device Specifies the device to use for command input and output.
/E:nnnnn Sets the initial environment size to nnnnn bytes. (nnnnn should be between 256 and 32,768).
/L:nnnn Specifies internal buffers length (requires /P as well). (nnnn should be between 128 and 1,024).
/U:nnn Specifies the input buffer length (requires /P as well). (nnn should be between 128 and 255).
/P Makes the new command interpreter permanent (can't exit).
/MSG Stores all error messages in memory (requires /P as well).
/LOW Forces COMMAND to keep its resident data in low memory.
/Y Steps through the batch program specified by /C or /K. Only available in MS-DOS 6.x and above.
/C command Executes the specified command and returns.
/K command Executes the specified command and continues running.
/Z Display the errorlevel of every command executed. Only available in MS-DOS 7.x and above.

查看英文版

查看中文版

command 示例

cmd

本示例打开cmd命令外壳。如果您已经在命令外壳中,并在命令行中运行“ cmd”或“ command”命令,则将打开一个新的Windows命令行。键入“退出”将退出新的命令行,并使您返回到原始命令行。

cmd

This example opens the cmd command shell. If you were already in a command shell and run the "cmd" or "command" command at the command line, a new Windows command line would be opened. Typing "exit" would exit the new command line and return you to the original command line.

查看英文版

查看中文版

其他命令行

cacls | call | CD | chcp | chdir | ctty | copy | convert | chkdsk | control | compact | chkntfs | choice | comp | cls | cipher | clip | color |

如此好文,分享给朋友
发表评论
验证码:
评论列表
共0条