CMD 命令速查手册
免费吧 http://www.freexo.com
显示或修改文件扩展名关联。 |
|
显示或更改文件属性。 |
|
设置或清除扩展式 CTRL+C 检查。 |
|
设置启动数据库中的属性以控制启动加载。 |
|
显示或修改文件的访问控制列表(ACL)。 |
|
显示当前目录的名称或将其更改。 |
|
显示或设置活动代码页数。 |
|
显示当前目录的名称或将其更改。 |
|
检查磁盘并显示状态报告。 |
|
显示或修改启动时间磁盘检查。 |
|
清除屏幕。 |
|
打开另一个 Windows 命令解释程序窗口。 |
|
设置默认控制台前景和背景颜色。 |
|
比较两个或两套文件的内容。 |
|
显示或更改 NTFS 分区上文件的压缩。 |
|
将 FAT 卷转换成 NTFS。您不能转换当前驱动器。 |
|
将至少一个文件复制到另一个位置。 |
|
显示或设置日期。 |
|
删除至少一个文件。 |
|
显示一个目录中的文件和子目录。 |
|
比较两个软盘的内容。 |
|
将一个软盘的内容复制到另一个软盘。 |
|
显示或配置磁盘分区属性。 |
|
编辑命令行、调用 Windows 命令并创建宏。 |
|
显示当前设备驱动程序状态和属性。 |
|
显示消息,或将命令回显打开或关上。 |
|
结束批文件中环境更改的本地化。 |
|
删除一个或多个文件。 |
|
退出 CMD.EXE 程序(命令解释程序)。 |
|
比较两个文件或两个文件集并显示它们之间的不同。 |
|
在一个或多个文件中搜索一个文字字符串。 |
|
在多个文件中搜索字符串。 |
|
为一套文件中的每个文件运行一个指定的命令。 |
|
格式化磁盘,以便跟 Windows 使用。 |
|
显示或配置文件系统的属性。 |
|
显示或修改用在文件扩展名关联的文件类型。 |
|
将 Windows 命令解释程序指向批处理程序中某个带标签的行。 |
|
显示机器或用户的组策略信息。 |
|
启用 Windows 在图形模式显示扩展字符集。 |
|
提供 Windows 命令的帮助信息。 |
|
显示、修改、备份或还原文件和目录的 ACL。 |
|
在批处理程序中执行有条件的处理过程。 |
|
创建、更改或删除磁盘的卷标。 |
|
创建一个目录。 |
|
创建一个目录。 |
|
创建符号链接和硬链接 |
|
配置系统设备。 |
|
逐屏显示输出。 |
|
将一个或多个文件从一个目录移动到另一个目录。 |
|
显示远程用户为了文件共享而打开的文件。 |
|
为可执行文件显示或设置搜索路径。 |
|
停止批处理文件的处理并显示信息。 |
|
还原由 PUSHD 保存的当前目录上一次的值。 |
|
打印一个文本文件。 |
|
改变 Windows 命令提示。 |
|
保存当前目录,然后对其进行更改。 |
|
删除目录。 |
|
从损坏的磁盘中恢复可读取的信息。 |
|
记录批处理文件或 CONFIG.SYS 中的注释。 |
|
重新命名文件。 |
|
重新命名文件。 |
|
替换文件。 |
|
删除目录。 |
|
复制文件和目录树的高级实用程序 |
|
显示、设置或删除 Windows 环境变量。 |
|
开始用批文件改变环境的本地化。 |
|
显示或配置服务(后台处理)。 |
|
安排命令和程序在一部计算机上按计划运行。 |
|
调整批处理文件中可替换参数的位置。 |
|
让机器在本地或远程正确关闭。 |
|
将输入排序。 |
|
打开单独视窗运行指定程序或命令。 |
|
将驱动器号与路径关联。 |
|
显示机器的具体的属性和配置。 |
|
显示包括服务的所有当前运行的任务。 |
|
终止正在运行的进程或应用程序。 |
|
显示或设置系统时间。 |
|
设置 CMD.EXE 会话的窗口标题。 |
|
以图形显示启动器或路径的目录结构。 |
|
显示文本文件的内容。 |
|
显示 Windows 的版本。 |
|
告诉 Windows 验证文件是否正确写入磁盘。 |
|
显示磁盘卷标和序列号。 |
|
复制文件和目录树。 |
|
在交互命令外壳里显示 WMI 信息。 |
* * * * * * *
显示或修改文件扩展名关联
ASSOC [.ext[=[fileType]]]
.ext 指定跟文件类型关联的文件扩展名
fileType 指定跟文件扩展名关联的文件类型
键入 ASSOC 而不带参数,显示当前文件关联。如果只用文件扩展
名调用 ASSOC,则显示那个文件扩展名的当前文件关联。如果不为
文件类型指定任何参数,命令会删除文件扩展名的关联。
Displays or modifies file extension associations
ASSOC [.ext[=[fileType]]]
.ext Specifies the file extension to associate the file type with
fileType Specifies the file type to associate with the file extension
Type ASSOC without parameters to display the current file associations.
If ASSOC is invoked with just a file extension, it displays the current
file association for that file extension. Specify nothing for the file
type and the command will delete the association for the file extension.
* * * * * * *
显示或更改文件属性。
ATTRIB [+R | -R] [+A | -A ] [+S | -S] [+H | -H] [+I | -I]
[drive:][path][filename] [/S [/D] [/L]]
+ 设置属性。
- 清除属性。
R 只读文件属性。
A 存档文件属性。
S 系统文件属性。
H 隐藏文件属性。
I 无内容索引文件属性。
[drive:][path][filename]
指定 attrib 要处理的文件。
/S 处理当前文件夹及其所有子文件夹中的匹配文件。
/D 也处理文件夹。
/L 处理符号链接和符号链接目标的属性。
Displays or changes file attributes.
ATTRIB [+R | -R] [+A | -A ] [+S | -S] [+H | -H] [+I | -I]
[drive:][path][filename] [/S [/D] [/L]]
+ Sets an attribute.
- Clears an attribute.
R Read-only file attribute.
A Archive file attribute.
S System file attribute.
H Hidden file attribute.
I Not content indexed file attribute.
[drive:][path][filename]
Specifies a file or files for attrib to process.
/S Processes matching files in the current folder
and all subfolders.
/D Processes folders as well.
/L Work on the attributes of the Symbolic Link versus
the target of the Symbolic Link
* * * * * * *
设置或清除 DOS 系统的扩展 CTRL+C 检测
这个命令是为了与 DOS 系统的兼容而保留的,在 Windows
里不起作用。
如果命令扩展被启用,并且操作平台是 Windows,
BREAK 命令会在被调试程序调试时输入一个硬代码中断点。
Sets or Clears Extended CTRL+C checking on DOS system
This is present for Compatibility with DOS systems. It has no effect
under Windows.
If Command Extensions are enabled, and running on the Windows
platform, then the BREAK command will enter a hard coded breakpoint
if being debugged by a debugger.
* * * * * * *
BCDEDIT - 启动配置数据存储编辑器
Bcdedit.exe 命令行工具修改启动配置数据存储。启动配置数据存储包含启动配置参数
并控制操作系统启动的方式。这些参数以前在 Boot.ini 文件中(在基于 BIOS 的操作
系统中)或在稳定 RAM 项中(在基于可扩展固件接口的操作系统中)。可以使用
Bcdedit.exe 在启动配置数据存储中添加、删除、编辑和附加项。
有关命令和选项的详细信息,请键入 bcdedit.exe /? <命令>。例如,若要显示
有关 /createstore 命令的详细信息,则键入:
bcdedit.exe /? /createstore
有关本帮助文件中按字母顺序排列的主题列表,请运行 "bcdedit /? TOPICS"。
对存储执行的命令
================================
/createstore 新建空的启动配置数据存储。
/export 将系统的内容导出到文件。以后可以使用该文件还原系统存储的状态。
/import 使用 /export 命令创建的备份文件来还原系统存储的状态。
对存储中的项执行的命令
===========================================
/copy 复制存储中的项。
/create 在存储中新建项。
/delete 删除存储中的项。
运行 bcdedit /? ID 获得有关这些命令使用的标识符的信息。
对项选项执行的命令
======================================
/deletevalue 删除存储中的项选项。
/set 设置存储中的项选项值。
运行 bcdedit /? TYPES 获得这些命令使用的数据类型的列表。
运行 bcdedit /? FORMATS 获得有效数据格式的列表。
控制输出的命令
============================
/enum 列出存储中的项。
/v 命令行选项,完整显示项标识符,而不是使用已知标识符的名称。
单独使用命令 /v 可完整显示 ACTIVE 类型的项标识符。
单独运行 "bcdedit" 等同于运行 "bcdedit /enum ACTIVE"。
控制启动管理器的命令
======================================
/bootsequence 为启动管理器设置一次性启动序列。
/default 设置启动管理器将使用的默认项。
/displayorder 设置启动管理器显示多重引导菜单的顺序。
/timeout 设置启动管理器的超时值。
/toolsdisplayorder 设置启动管理器显示工具菜单的顺序。
控制启动应用程序紧急管理服务的命令
==========================================================================
/bootems 启用或禁用启动应用程序的紧急管理服务。
/ems 启用或禁用操作系统项的紧急管理服务。
/emssettings 设置全局紧急管理服务参数。
控制调试的命令
==============================
/bootdebug 启用或禁用启动应用程序的启动调试。
/dbgsettings 设置全局调试程序参数。
/debug 启用或禁用操作系统项的内核调试。
BCDEDIT - Boot Configuration Data Store Editor
The Bcdedit.exe command-line tool modifies the boot configuration data store.
The boot configuration data store contains boot configuration parameters and
controls how the operating system is booted. These parameters were previously
in the Boot.ini file (in BIOS-based operating systems) or in the nonvolatile
RAM entries (in Extensible Firmware Interface-based operating systems). You can
use Bcdedit.exe to add, delete, edit, and append entries in the boot
configuration data store.
For detailed command and option information, type bcdedit.exe /? . For
example, to display detailed information about the /createstore command, type:
bcdedit.exe /? /createstore
For an alphabetical list of topics in this help file, run "bcdedit /? TOPICS".
Commands that operate on a store
================================
/createstore Creates a new and empty boot configuration data store.
/export Exports the contents of the system store to a file. This file
can be used later to restore the state of the system store.
/import Restores the state of the system store using a backup file
created with the /export command.
Commands that operate on entries in a store
===========================================
/copy Makes copies of entries in the store.
/create Creates new entries in the store.
/delete Deletes entries from the store.
Run bcdedit /? ID for information about identifiers used by these commands.
Commands that operate on entry options
======================================
/deletevalue Deletes entry options from the store.
/set Sets entry option values in the store.
Run bcdedit /? TYPES for a list of datatypes used by these commands.
Run bcdedit /? FORMATS for a list of valid data formats.
Commands that control output
============================
/enum Lists entries in the store.
/v Command-line option that displays entry identifiers in full,
rather than using names for well-known identifiers.
Use /v by itself as a command to display entry identifiers
in full for the ACTIVE type.
Running "bcdedit" by itself is equivalent to running "bcdedit /enum ACTIVE".
Commands that control the boot manager
======================================
/bootsequence Sets the one-time boot sequence for the boot manager.
/default Sets the default entry that the boot manager will use.
/displayorder Sets the order in which the boot manager displays the
multiboot menu.
/timeout Sets the boot manager time-out value.
/toolsdisplayorder Sets the order in which the boot manager displays
the tools menu.
Commands that control Emergency Management Services for a boot application
==========================================================================
/bootems Enables or disables Emergency Management Services
for a boot application.
/ems Enables or disables Emergency Management Services for an
operating system entry.
/emssettings Sets the global Emergency Management Services parameters.
Command that control debugging
==============================
/bootdebug Enables or disables boot debugging for a boot application.
/dbgsettings Sets the global debugger parameters.
/debug Enables or disables kernel debugging for an operating system
entry.
* * * * * * *
注意: 有些人反对使用 Cacls,请使用 Icacls。
显示或者修改文件的访问控制列表(ACL)
CACLS filename [/T] [/M] [/L] [/S[:SDDL]] [/E] [/C] [/G user:perm]
[/R user [...]] [/P user:perm [...]] [/D user [...]]
filename 显示 ACL。
/T 更改当前目录及其所有子目录中
指定文件的 ACL。
/L 对照目标处理符号链接本身
/M 更改装载到目录的卷的 ACL
/S 显示 DACL 的 SDDL 字符串。
/S:SDDL 使用在 SDDL 字符串中指定的 ACL 替换 ACL。
(/E、/G、/R、/P 或 /D 无效)。
/E 编辑 ACL 而不替换。
/C 在出现拒绝访问错误时继续。
/G user:perm 赋予指定用户访问权限。
Perm 可以是: R 读取
W 写入
C 更改(写入)
F 完全控制
/R user 撤销指定用户的访问权限(仅在与 /E 一起使用时合法)。
/P user:perm 替换指定用户的访问权限。
Perm 可以是: N 无
R 读取
W 写入
C 更改(写入)
F 完全控制
/D user 拒绝指定用户的访问。
在命令中可以使用通配符指定多个文件。
也可以在命令中指定多个用户。
缩写:
CI - 容器继承。
ACE 会由目录继承。
OI - 对象继承。
ACE 会由文件继承。
IO - 只继承。
ACE 不适用于当前文件/目录。
ID - 已继承。
ACE 从父目录的 ACL 继承。
NOTE: Cacls is now deprecated, please use Icacls.
Displays or modifies access control lists (ACLs) of files
CACLS filename [/T] [/M] [/L] [/S[:SDDL]] [/E] [/C] [/G user:perm]
[/R user [...]] [/P user:perm [...]] [/D user [...]]
filename Displays ACLs.
/T Changes ACLs of specified files in
the current directory and all subdirectories.
/L Work on the Symbolic Link itself versus the target
/M Changes ACLs of volumes mounted to a directory
/S Displays the SDDL string for the DACL.
/S:SDDL Replaces the ACLs with those specified in the SDDL string
(not valid with /E, /G, /R, /P, or /D).
/E Edit ACL instead of replacing it.
/C Continue on access denied errors.
/G user:perm Grant specified user access rights.
Perm can be: R Read
W Write
C Change (write)
F Full control
/R user Revoke specified user's access rights (only valid with /E).
/P user:perm Replace specified user's access rights.
Perm can be: N None
R Read
W Write
C Change (write)
F Full control
/D user Deny specified user access.
Wildcards can be used to specify more that one file in a command.
You can specify more than one user in a command.
Abbreviations:
CI - Container Inherit.
The ACE will be inherited by directories.
OI - Object Inherit.
The ACE will be inherited by files.
IO - Inherit Only.
The ACE does not apply to the current file/directory.
ID - Inherited.
The ACE was inherited from the parent directory's ACL.
* * * * * * *
从批处理程序调用另一个批处理程序。
CALL [drive:][path]filename [batch-parameters]
batch-parameters 指定批处理程序所需的命令行信息。
如果命令扩展被启用,CALL 会如下改变:
CALL 命令现在将卷标当作 CALL 的目标接受。语法是:
CALL:label arguments
一个新的批文件上下文由指定的参数所创建,控制在卷标被指定
后传递到语句。您必须通过达到批脚本文件末两次来 "exit" 两次。
第一次读到文件末时,控制会回到 CALL 语句的紧后面。第二次
会退出批脚本。键入 GOTO /?,参看 GOTO :EOF 扩展的描述,
此描述允许您从一个批脚本返回。
另外,批脚本文本参数参照(%0、%1、等等)已如下改变:
批脚本里的 %* 指出所有的参数(如 %1 %2 %3 %4 %5 ...)
批参数(%n)的替代已被增强。您可以使用以下语法:
%~1 - 删除引号("),扩展 %1
%~f1 - 将 %1 扩展到一个完全合格的路径名
%~d1 - 仅将 %1 扩展到一个驱动器号
%~p1 - 仅将 %1 扩展到一个路径
%~n1 - 仅将 %1 扩展到一个文件名
%~x1 - 仅将 %1 扩展到一个文件扩展名
%~s1 - 扩展的路径只含有短名
%~a1 - 将 %1 扩展到文件属性
%~t1 - 将 %1 扩展到文件的日期/时间
%~z1 - 将 %1 扩展到文件的大小
%~$PATH:1 - 查找列在 PATH 环境变量的目录,并将 %1
扩展到找到的第一个完全合格的名称。如果
环境变量名未被定义,或者没有找到文件,
此修改符会扩展到空字符串
可以组合修改符来取得多重结果:
%~dp1 - 只将 %1 扩展到驱动器号和路径
%~nx1 - 只将 %1 扩展到文件名和扩展名
%~dp$PATH:1 - 在列在 PATH 环境变量中的目录里查找 %1,
并扩展到找到的第一个文件的驱动器号和路径。
%~ftza1 - 将 %1 扩展到类似 DIR 的输出行。
在上面的例子中,%1 和 PATH 可以被其他有效数值替换。
%~ 语法被一个有效参数号码终止。%~ 修定符不能跟 %*
使用
Calls one batch program from another.
CALL [drive:][path]filename [batch-parameters]
batch-parameters Specifies any command-line information required by the
batch program.
If Command Extensions are enabled CALL changes as follows:
CALL command now accepts labels as the target of the CALL. The syntax
is:
CALL :label arguments
A new batch file context is created with the specified arguments and
control is passed to the statement after the label specified. You must
"exit" twice by reaching the end of the batch script file twice. The
first time you read the end, control will return to just after the CALL
statement. The second time will exit the batch script. Type GOTO /?
for a description of the GOTO :EOF extension that will allow you to
"return" from a batch script.
In addition, expansion of batch script argument references (%0, %1,
etc.) have been changed as follows:
%* in a batch script refers to all the arguments (e.g. %1 %2 %3
%4 %5 ...)
Substitution of batch parameters (%n) has been enhanced. You can
now use the following optional syntax:
%~1 - expands %1 removing any surrounding quotes (")
%~f1 - expands %1 to a fully qualified path name
%~d1 - expands %1 to a drive letter only
%~p1 - expands %1 to a path only
%~n1 - expands %1 to a file name only
%~x1 - expands %1 to a file extension only
%~s1 - expanded path contains short names only
%~a1 - expands %1 to file attributes
%~t1 - expands %1 to date/time of file
%~z1 - expands %1 to size of file
%~$PATH:1 - searches the directories listed in the PATH
environment variable and expands %1 to the fully
qualified name of the first one found. If the
environment variable name is not defined or the
file is not found by the search, then this
modifier expands to the empty string
The modifiers can be combined to get compound results:
%~dp1 - expands %1 to a drive letter and path only
%~nx1 - expands %1 to a file name and extension only
%~dp$PATH:1 - searches the directories listed in the PATH
environment variable for %1 and expands to the
drive letter and path of the first one found.
%~ftza1 - expands %1 to a DIR like output line
In the above examples %1 and PATH can be replaced by other
valid values. The %~ syntax is terminated by a valid argument
number. The %~ modifiers may not be used with %*
* * * * * * *
显示当前目录名或改变当前目录。
CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]
.. 指定要改成父目录。
键入 CD drive: 显示指定驱动器中的当前目录。
不带参数只键入 CD,则显示当前驱动器和目录。
使用 /D 开关,除了改变驱动器的当前目录之外,
还可改变当前驱动器。
如果命令扩展被启用,CHDIR 会如下改变:
当前的目录字符串会被转换成使用磁盘名上的大小写。所以,
如果磁盘上的大小写如此,CD C:"TEMP 会将当前目录设为
C:"Temp。
CHDIR 命令不把空格当作分隔符,因此有可能将目录名改为一个
带有空格但不带有引号的子目录名。例如:
cd "winnt"profiles"username"programs"start menu
与下列相同:
cd ""winnt"profiles"username"programs"start menu"
在扩展停用的情况下,您必须键入以上命令。
Displays the name of or changes the current directory.
CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]
.. Specifies that you want to change to the parent directory.
Type CD drive: to display the current directory in the specified drive.
Type CD without parameters to display the current drive and directory.
Use the /D switch to change current drive in addition to changing current
directory for a drive.
If Command Extensions are enabled CHDIR changes as follows:
The current directory string is converted to use the same case as
the on disk names. So CD C:"TEMP would actually set the current
directory to C:"Temp if that is the case on disk.
CHDIR command does not treat spaces as delimiters, so it is possible to
CD into a subdirectory name that contains a space without surrounding
the name with quotes. For example:
cd "winnt"profiles"username"programs"start menu
is the same as:
cd ""winnt"profiles"username"programs"start menu"
which is what you would have to type if extensions were disabled.
* * * * * * *
显示或设置活动代码页编号。
CHCP [nnn]
nnn 指定代码页编号。
不加参数键入 CHCP 显示活动代码页编号。
Displays or sets the active code page number.
CHCP [nnn]
nnn Specifies a code page number.
Type CHCP without a parameter to display the active code page number.
* * * * * * *
显示当前目录名或改变当前目录。
CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]
.. 指定要改成父目录。
键入 CD drive: 显示指定驱动器中的当前目录。
不带参数只键入 CD,则显示当前驱动器和目录。
使用 /D 开关,除了改变驱动器的当前目录之外,
还可改变当前驱动器。
如果命令扩展被启用,CHDIR 会如下改变:
当前的目录字符串会被转换成使用磁盘名上的大小写。所以,
如果磁盘上的大小写如此,CD C:"TEMP 会将当前目录设为
C:"Temp。
CHDIR 命令不把空格当作分隔符,因此有可能将目录名改为一个
带有空格但不带有引号的子目录名。例如:
cd "winnt"profiles"username"programs"start menu
与下列相同:
cd ""winnt"profiles"username"programs"start menu"
在扩展停用的情况下,您必须键入以上命令。
Displays the name of or changes the current directory.
CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]
.. Specifies that you want to change to the parent directory.
Type CD drive: to display the current directory in the specified drive.
Type CD without parameters to display the current drive and directory.
Use the /D switch to change current drive in addition to changing current
directory for a drive.
If Command Extensions are enabled CHDIR changes as follows:
The current directory string is converted to use the same case as
the on disk names. So CD C:"TEMP would actually set the current
directory to C:"Temp if that is the case on disk.
CHDIR command does not treat spaces as delimiters, so it is possible to
CD into a subdirectory name that contains a space without surrounding
the name with quotes. For example:
cd "winnt"profiles"username"programs"start menu
is the same as:
cd ""winnt"profiles"username"programs"start menu"
which is what you would have to type if extensions were disabled.
* * * * * * *
检查磁盘并显示状态报告。
CHKDSK [volume[[path]filename]]] [/F] [/V] [/R] [/X] [/I] [/C] [/L[:size]]
volume 指定驱动器号(后面跟一个冒号)、装入点或卷名。
filename 仅用于 FAT/FAT32: 指定要检查是否有碎片的文件。
/F 修复磁盘上的错误。
/V 在 FAT/FAT32 上: 显示磁盘上每个文件的完整路径和名称。
在 NTFS 上: 如果有清除消息,则显示。
/R 查找损坏的扇区并恢复可读信息(隐含 /F)。
/L:size 仅用于 NTFS: 将日志文件大小更改为指定的 KB 数。如果没
有指定大小,则显示当前的大小。
/X 如果必要,强制先卸下卷。之后该卷的所有打开的句柄都会无效
(隐含 /F)。
/I 仅用于 NTFS: 对索引项进行强度较小的检查。
/C 仅用于 NTFS: 跳过文件夹结构的循环检查。
/B 仅用于 NTFS: 重新评估该卷上不正确的群集(隐含 /R)
/I 或 /C 开关通过跳过对该卷的某些检查,可减少运行 Chkdsk 所需的时间。
Checks a disk and displays a status report.
CHKDSK [volume[[path]filename]]] [/F] [/V] [/R] [/X] [/I] [/C] [/L[:size]] [/B]
volume Specifies the drive letter (followed by a colon),
mount point, or volume name.
filename FAT/FAT32 only: Specifies the files to check for fragmentation.
/F Fixes errors on the disk.
/V On FAT/FAT32: Displays the full path and name of every file
on the disk.
On NTFS: Displays cleanup messages if any.
/R Locates bad sectors and recovers readable information
(implies /F).
/L:size NTFS only: Changes the log file size to the specified number
of kilobytes. If size is not specified, displays current
size.
/X Forces the volume to dismount first if necessary.
All opened handles to the volume would then be invalid
(implies /F).
/I NTFS only: Performs a less vigorous check of index entries.
/C NTFS only: Skips checking of cycles within the folder
structure.
/B NTFS only: Re-evaluates bad clusters on the volume
(implies /R)
The /I or /C switch reduces the amount of time required to run Chkdsk by
skipping certain checks of the volume.
* * * * * * *
在启动时显示或修改磁盘检查。
CHKNTFS volume [...]
CHKNTFS /D
CHKNTFS /T[:time]"r"r
CHKNTFS /X volume [...]
CHKNTFS /C volume [...]
volume 指定驱动器号(后面跟一个冒号)、装入点或卷名。
/D 将计算机恢复成默认状态,启动时检查所有驱动器,并对有问
题的驱动器执行 chkdsk 命令。
/T:time 将 AUTOCHK 初始递减计数时间改成指定的时间,单位为秒数。
如果没有指定时间,则显示当前设置。
/X 排除启动时不作检查的驱动器。上次执行此命令排除的驱动器此
时无效。
/C 安排启动时检查驱动器,如果驱动器有问题,运行 chkdsk。
如果没有指定命令行开关,CHKNTFS 会显示每一驱动器有问题的位的状态。
Displays or modifies the checking of disk at boot time.
CHKNTFS volume [...]
CHKNTFS /D
CHKNTFS /T[:time]
CHKNTFS /X volume [...]
CHKNTFS /C volume [...]
volume Specifies the drive letter (followed by a colon),
mount point, or volume name.
/D Restores the machine to the default behavior; all drives are
checked at boot time and chkdsk is run on those that are
dirty.
/T:time Changes the AUTOCHK initiation countdown time to the
specified amount of time in seconds. If time is not
specified, displays the current setting.
/X Excludes a drive from the default boot-time check. Excluded
drives are not accumulated between command invocations.
/C Schedules a drive to be checked at boot time; chkdsk will run
if the drive is dirty.
If no switches are specified, CHKNTFS will display if the specified drive is
dirty or scheduled to be checked on next reboot.
* * * * * * *
清除屏幕。
CLS
Clears the screen.
CLS
* * * * * * *
启动 Windows 命令解释器的一个新实例
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 禁止从注册表执行 AutoRun 命令(见下)
/A 使向管道或文件的内部命令输出成为 ANSI
/U 使向管道或文件的内部命令输出成为
Unicode
/T:fg 设置前台/背景颜色(详细信息见 COLOR /?)
/E:ON 启用命令扩展(见下)
/E:OFF 禁用命令扩展(见下)
/F:ON 启用文件和目录名完成字符(见下)
/F:OFF 禁用文件和目录名完成字符(见下)
/V:ON 使用 ! 作为分隔符启用延迟的环境变量
扩展。例如,/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,为某一
特定调用而停用扩展。您可以在机器上和/或用户登录会话上
启用或停用 CMD.EXE 所有调用的扩展,这要通过设置使用
REGEDT.EXE 的注册表中的一个或两个 REG_DWORD 值:
HKEY_LOCAL_MACHINE"Software"Microsoft"Command Processor"EnableExtensions
和/或
HKEY_CURRENT_USER"Software"Microsoft"Command Processor"EnableExtensions
到 0x1 或 0x0。用户特定设置比机器设置有优先权。命令行
开关比注册表设置有优先权。
命令扩展包括对下列命令所做的更改和/或添加:
DEL 或 ERASE
COLOR
CD 或 CHDIR
MD 或 MKDIR
PROMPT
PUSHD
POPD
SET
SETLOCAL
ENDLOCAL
IF
FOR
CALL
SHIFT
GOTO
START (同时包括对外部命令调用所做的更改)
ASSOC
FTYPE
有关特定详细信息,请键入 commandname /? 查看。
延迟环境变量扩展不按默认值启用。您可以用/V:ON 或 /V:OFF
开关,为 CMD.EXE 的某个调用而启用或停用延迟环境变量扩展。
您可以在机器上和/或用户登录会话上启用或停用 CMD.EXE 所有
调用的延迟扩展,这要通过设置使用 REGEDT.EXE 的注册表中的
一个或两个 REG_DWORD 值:
HKEY_LOCAL_MACHINE"Software"Microsoft"Command Processor"DelayedExpansion
和/或
HKEY_CURRENT_USER"Software"Microsoft"Command Processor"DelayedExpansion
到 0x1 或 0x0。用户特定设置比机器设置有优先权。命令行开关
比注册表设置有优先权。
如果延迟环境变量扩展被启用,惊叹号字符可在执行时间,被用来
代替一个环境变量的数值。
您可以用 /F:ON 或 /F:OFF 开关为 CMD.EXE 的某个
调用而启用或禁用文件名完成。您可以在计算上和/或
用户登录会话上启用或禁用 CMD.EXE 所有调用的完成,
这可以通过使用 REGEDIT.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),就会使用目录
完成。
用引号将相符路径括起来,完成代码可以正确处理含有空格
或其他特殊字符的文件名。同时,如果备份,然后从行内调用
文件完成,完成被调用时位于光标右方的文字会被调用。
需要引号的特殊字符是:
()[]{}^=;!'+,`~(&()
Starts a new instance of the Windows 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 ! 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 string if 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, then 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 of 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: &<>()@^|
- 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 and 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
and/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 on a
machine and/or user logon session by setting either or both of the
following REG_DWORD values in the registry using REGEDIT.EXE:
HKEY_LOCAL_MACHINE"Software"Microsoft"Command Processor"EnableExtensions
and/or
HKEY_CURRENT_USER"Software"Microsoft"Command Processor"EnableExtensions
to either 0x1 or 0x0. 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 and/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 commandname /? to view the specifics.
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. You
can enable or disable delayed expansion for all invocations of CMD.EXE on a
machine and/or user logon session by setting either or both of the
following REG_DWORD values in the registry using REGEDIT.EXE:
HKEY_LOCAL_MACHINE"Software"Microsoft"Command Processor"DelayedExpansion
and/or
HKEY_CURRENT_USER"Software"Microsoft"Command Processor"DelayedExpansion
to either 0x1 or 0x0. 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 be used to substitute the value of an environment variable
at execution time.
You can enable or disable file name completion for a particular
invocation of CMD.EXE with the /F:ON or /F:OFF switch. You can enable
or disable completion for all invocations of CMD.EXE on a machine and/or
user logon session by setting either or both of the following REG_DWORD
values in the registry using REGEDIT.EXE:
HKEY_LOCAL_MACHINE"Software"Microsoft"Command Processor"CompletionChar
HKEY_LOCAL_MACHINE"Software"Microsoft"Command Processor"PathCompletionChar
and/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 takes the path string to the left
of the cursor appends a wild card character to it if none is already
present and builds up a list of paths that match. It then displays the
first matching path. If no paths match, it just beeps and leaves the
display alone. Thereafter, repeated pressing of the same control
character will cycle through the list of matching paths. Pressing the
Shift key with the control character will move 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 only 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:
&()[]{}^=;!'+,`~
* * * * * * *
设置默认的控制台前景和背景颜色。
COLOR [attr]
attr 指定控制台输出的颜色属性
颜色属性由两个十六进制数字指定 -- 第一个为背景,第二个则为
前景。每个数字可以为以下任何值之一:
0 = 黑色 8 = 灰色
1 = 蓝色 9 = 淡蓝色
2 = 绿色 A = 淡绿色
3 = 浅绿色 B = 淡浅绿色
4 = 红色 C = 淡红色
5 = 紫色 D = 淡紫色
6 = 黄色 E = 淡黄色
7 = 白色 F = 亮白色
如果没有给定任何参数,该命令会将颜色还原到 CMD.EXE 启动时
的颜色。这个值来自当前控制台窗口、/T 命令行开关或
DefaultColor 注册表值。
如果用相同的前景和背景颜色来执行 COLOR 命令,COLOR 命令
会将 ERRORLEVEL 设置为 1。
例如: "COLOR fc" 在亮白色上产生亮红色
Sets the default console foreground and background colors.
COLOR [attr]
attr Specifies color attribute of console output
Color attributes are specified by TWO hex digits -- the first
corresponds to the background; the second the foreground. Each digit
can be any of the following values:
0 = Black 8 = Gray
1 = Blue 9 = Light Blue
2 = Green A = Light Green
3 = Aqua B = Light Aqua
4 = Red C = Light Red
5 = Purple D = Light Purple
6 = Yellow E = Light Yellow
7 = White F = Bright White
If no argument is given, this command restores the color to what it was
when CMD.EXE started. This value either comes from the current console
window, the /T command line switch or from the DefaultColor registry
value.
The COLOR command sets ERRORLEVEL to 1 if an attempt is made to execute
the COLOR command with a foreground and background color that are the
same.
Example: "COLOR fc" produces light red on bright white
* * * * * * *
比较两个文件或两个文件集的内容。
COMP [data1] [data2] [/D] [/A] [/L] [/N=number] [/C] [/OFF[LINE]]
data1 指定要比较的第一个文件的位置和名称。
data2 指定要比较的第二个文件的位置和名称。
/D 用十进制格式显示不同处。
/A 用 ASCII 字符显示不同处。
/L 显示不同的行数。
/N=number 只比较每个文件中第一个指定的行数。
/C 比较文件时不分 ASCII 字母的大小写。
/OFF[LINE] 不要跳过带有脱机属性集的文件。
要比较文件集,在 data1 和 data2 参数中使用通配符。
Compares the contents of two files or sets of files.
COMP [data1] [data2] [/D] [/A] [/L] [/N=number] [/C] [/OFF[LINE]]
data1 Specifies location and name(s) of first file(s) to compare.
data2 Specifies location and name(s) of second files to compare.
/D Displays differences in decimal format.
/A Displays differences in ASCII characters.
/L Displays line numbers for differences.
/N=number Compares only the first specified number of lines in each file.
/C Disregards case of ASCII letters when comparing files.
/OFF[LINE] Do not skip files with offline attribute set.
To compare sets of files, use wildcards in data1 and data2 parameters.
* * * * * * *
显示或改变 NTFS 分区上文件的压缩.
COMPACT [/C | /U] [/S[:dir]] [/A] [/I] [/F] [/Q] [filename [...]]
/C 压缩指定的文件。会给目录作标记,这样以后添加的文件
会得到压缩。
/U 解压缩指定的文件。会给目录作标记,这样以后添加的文
件不会得到压缩。
/S 在指定的目录和所有子目录中的文件上执行指定操作。
默认 "dir"是当前目录。
/A 显示具有隐藏或系统属性的文件。在默认
情况下,这些文件都是被忽略的。
/I 即使在错误发生后,依然继续执行指定的操作。在默认情况
下,COMPACT 在遇到错误时会停止。
/F 在所有指定文件上强制压缩操作,包括已被压缩的文件。
在默认情况下,已经压缩的文件被忽略。
/Q 只报告最重要的信息。
filename 指定类型、文件和目录。
不跟参数一起使用时,COMPACT 显示当前目录及其所含文件的
压缩状态。您可以使用多个文件名和通配符。在多个参数之间
必须加空格。
Displays or alters the compression of files on NTFS partitions.
COMPACT [/C | /U] [/S[:dir]] [/A] [/I] [/F] [/Q] [filename [...]]
/C Compresses the specified files. Directories will be marked
so that files added afterward will be compressed.
/U Uncompresses the specified files. Directories will be marked
so that files added afterward will not be compressed.
/S Performs the specified operation on files in the given
directory and all subdirectories. Default "dir" is the
current directory.
/A Displays files with the hidden or system attributes. These
files are omitted by default.
/I Continues performing the specified operation even after errors
have occurred. By default, COMPACT stops when an error is
encountered.
/F Forces the compress operation on all specified files, even
those which are already compressed. Already-compressed files
are skipped by default.
/Q Reports only the most essential information.
filename Specifies a pattern, file, or directory.
Used without parameters, COMPACT displays the compression state of
the current directory and any files it contains. You may use multiple
filenames and wildcards. You must put spaces between multiple
parameters.
* * * * * * *
将 FAT 卷转换成 NTFS。
CONVERT volume /FS:NTFS [/V] [/CvtArea:filename] [/NoSecurity] [/X]
volume 指定驱动器号(后面跟一个冒号)、装入点或卷名。
/FS:NTFS 指定要将此卷转换成 NTFS。
/V 指定将用详细模式运行转换。
/CvtArea:filename
将根目录中的一个连续文件指定为
NTFS 系统文件的占位符。
/NoSecurity 指定所有用户均可以访问转换文件和目录的安全设置。
/X 如果必要,先强行卸除卷。
该卷的所有打开的句柄将无效。
Converts a FAT volume to NTFS.
CONVERT volume /FS:NTFS [/V] [/CvtArea:filename] [/NoSecurity] [/X]
volume Specifies the drive letter (followed by a colon),
mount point, or volume name.
/FS:NTFS Specifies that the volume will be converted to NTFS.
/V Specifies that Convert will be run in verbose mode.
/CvtArea:filename
Specifies a contiguous file in the root directory
that will be the place holder for NTFS system files.
/NoSecurity Specifies that the security settings on the converted
files and directories allow access by all users.
/X Forces the volume to dismount first if necessary.
All open handles to the volume will not be valid.
* * * * * * *
将一份或多份文件复制到另一个位置。
COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/L] [/A | /B ] source [/A | /B]
[+ source [/A | /B] [+ ...]] [destination [/A | /B]]
source 指定要复制的文件。
/A 表示一个 ASCII 文本文件。
/B 表示一个二进位文件。
/D 允许解密要创建的目标文件
destination 为新文件指定目录和/或文件名。
/V 验证新文件写入是否正确。
/N 复制带有非 8dot3 名称的文件时,
尽可能使用短文件名。
/Y 不使用确认是否要覆盖现有目标文件
的提示。
/-Y 使用确认是否要覆盖现有目标文件
的提示。
/Z 用可重新启动模式复制已联网的文件。
/L 如果源是符号链接,请将链接复制
到目标而不是源链接指向的实际文件。
命令行开关 /Y 可以在 COPYCMD 环境变量中预先设定。
这可能会被命令行上的 /-Y 替代。除非 COPY
命令是在一个批处理脚本中执行的,默认值应为
在覆盖时进行提示。
要附加文件,请为目标指定一个文件,为源指定
数个文件(用通配符或 file1+file2+file3 格式)。
Copies one or more files to another location.
COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/L] [/A | /B ] source [/A | /B]
[+ source [/A | /B] [+ ...]] [destination [/A | /B]]
source Specifies the file or files to be copied.
/A Indicates an ASCII text file.
/B Indicates a binary file.
/D Allow the destination file to be created decrypted
destination Specifies the directory and/or filename for the new file(s).
/V Verifies that new files are written correctly.
/N Uses short filename, if available, when copying a file with a
non-8dot3 name.
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.
/-Y Causes prompting to confirm you want to overwrite an
existing destination file.
/Z Copies networked files in restartable mode.
/L If the source is a symbolic link, copy the link to the target
instead of the actual file the source link points to.
The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line. Default is
to prompt on overwrites unless COPY command is being executed from
within a batch script.
To append files, specify a single file for destination, but multiple files
for source (using wildcards or file1+file2+file3 format).
* * * * * * *
显示或设置日期。
DATE [/T | date]
显示当前日期设置和输入新日期的提示,请键入
不带参数的 DATE。要保留现有日期,请按 ENTER。
如果命令扩展被启用,DATE 命令会支持 /T 开关;
该开关指示命令只输出当前日期,但不提示输入新日期。
Displays or sets the date.
DATE [/T | date]
Type DATE without parameters to display the current date setting and
a prompt for a new one. Press ENTER to keep the same date.
If Command Extensions are enabled the DATE command supports
the /T switch which tells the command to just output the
current date, without prompting for a new date.
* * * * * * *
删除一个或数个文件。
DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
ERASE [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
names 指定一个或多个文件或者目录列表。
通配符可用来删除多个文件。
如果指定了一个目录,该目录中的所
有文件都会被删除。
/P 删除每一个文件之前提示确认。
/F 强制删除只读文件。
/S 删除所有子目录中的指定的文件。
/Q 安静模式。删除全局通配符时,不要求确认
/A 根据属性选择要删除的文件
属性 R 只读文件 S 系统文件
H 隐藏文件 A 存档文件
I 无内容索引文件 L 重分析点
- 表示“否”的前缀
如果命令扩展被启用,DEL 和 ERASE 更改如下:
/S 开关的显示句法会颠倒,即只显示已经
删除的文件,而不显示找不到的文件。
Deletes one or more files.
DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
ERASE [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
names Specifies a list of one or more files or directories.
Wildcards may be used to delete multiple files. If a
directory is specified, all files within the directory
will be deleted.
/P Prompts for confirmation before deleting each file.
/F Force deleting of read-only files.
/S Delete specified files from all subdirectories.
/Q Quiet mode, do not ask if ok to delete on global wildcard
/A Selects files to delete based on attributes
attributes R Read-only files S System files
H Hidden files A Files ready for archiving
I Not content indexed Files L Reparse Points
- Prefix meaning not
If Command Extensions are enabled DEL and ERASE change as follows:
The display semantics of the /S switch are reversed in that it shows
you only the files that are deleted, not the ones it could not find.
* * * * * * *
显示目录中的文件和子目录列表。
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]
指定要列出的驱动器、目录和/或文件。
/A 显示具有指定属性的文件。
属性 D 目录 R 只读文件
H 隐藏文件 A 准备存档的文件
S 系统文件 I 无内容索引文件
L 解析点 - 表示“否”的前缀
/B 使用空格式(没有标题信息或摘要)。
/C 在文件大小中显示千位数分隔符。这是默认值。用 /-C 来
禁用分隔符显示。
/D 跟宽式相同,但文件是按栏分类列出的。
/L 用小写。
/N 新的长列表格式,其中文件名在最右边。
/O 用分类顺序列出文件。
排列顺序 N 按名称(字母顺序) S 按大小(从小到大)
E 按扩展名(字母顺序) D 按日期/时间(从先到后)
G 组目录优先 - 反转顺序的前缀
/P 在每个信息屏幕后暂停。
/Q 显示文件所有者。
/R 显示文件的备用数据流。
/S 显示指定目录和所有子目录中的文件。
/T 控制显示或用来分类的时间字符域。
时间段 C 创建时间
A 上次访问时间
W 上次写入的时间
/W 用宽列表格式。
/X 显示为非 8.3 文件名产生的短名称。格式是 /N 的格式,
短名称插在长名称前面。如果没有短名称,在其位置则
显示空白。
/4 用四位数字显示年
可以在 DIRCMD 环境变量中预先设定开关。通过添加前缀 - (破折号)
来替代预先设定的开关。例如,/-W。
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.
* * * * * * *
比较两张软盘的内容。
DISKCOMP [drive1: [drive2:]]
Compares the contents of two floppy disks.
DISKCOMP [drive1: [drive2:]]
* * * * * * *
把一张软盘的内容复制到另一张。
DISKCOPY [drive1: [drive2:]] [/V]
/V 校验信息复制得是否正确。
两张软盘的类型必须相同。
您可以为 drive1 和 drive2 指定同样的驱动器。
Copies the contents of one floppy disk to another.
DISKCOPY [drive1: [drive2:]] [/V]
/V Verifies that the information is copied correctly.
The two floppy disks must be the same type.
You may specify the same drive for drive1 and drive2.
* * * * * * *
Microsoft DiskPart 语法:
diskpart [/s <script>] [/?]
/s <script> - 使用一个 DiskPart 脚本。
/? - 显示这个帮助屏幕。
Microsoft DiskPart syntax:
diskpart [/s <script>] [/?]
/s <script> - Use a DiskPart script.
/? - Show this help screen.
* * * * * * *
编辑命令行,重调用 Windows 命令,并创建宏。
DOSKEY [/REINSTALL] [/LISTSIZE=size] [/MACROS[:ALL | :exename]]
[/HISTORY] [/INSERT | /OVERSTRIKE] [/EXENAME=exename] [/MACROFILE=filename]
[macroname=[text]]
/REINSTALL 安装一组新的 Doskey。
/LISTSIZE=size 设置命令历史记录的缓冲区大小。
/MACROS 显示所有 Doskey 宏。
/MACROS:ALL 为具有 Doskey 宏的执行文件,显示所有的 Doskey 宏。
/MACROS:exename 显示指定执行文件的所有 Doskey 宏。
/HISTORY 显示保存在内存中的所有命令。
/INSERT 指定用键入的新文字插入旧文字中。
/OVERSTRIKE 指定新文字覆盖旧文字。
/EXENAME=exename 指定执行文件。
/MACROFILE=filename 指定安装的宏文件。
macroname 指定所创建宏的名称。
text 指定要登记的命令。
使用上下箭头键选择命令;ESC 清除命令行;F7 显示命令历史记录; ALT+F7 清除
命令历史记录;F8 搜索命令历史记录; F9 按编号选择命令; ALT+F10 清除宏定义。
以下是 Doskey 宏定义的特殊码:
$T 命令分隔符号。允许一个宏可以含多个命令。
$1-$9 批处理参数。与批处理程序中的 %1-%9 相同。
$* 以命令行中命令名称后面的任何内容替换的符号。
Edits command lines, recalls Windows commands, and creates macros.
DOSKEY [/REINSTALL] [/LISTSIZE=size] [/MACROS[:ALL | :exename]]
[/HISTORY] [/INSERT | /OVERSTRIKE] [/EXENAME=exename] [/MACROFILE=filename]
[macroname=[text]]
/REINSTALL Installs a new copy of Doskey.
/LISTSIZE=size Sets size of command history buffer.
/MACROS Displays all Doskey macros.
/MACROS:ALL Displays all Doskey macros for all executables which have
Doskey macros.
/MACROS:exename Displays all Doskey macros for the given executable.
/HISTORY Displays all commands stored in memory.
/INSERT Specifies that new text you type is inserted in old text.
/OVERSTRIKE Specifies that new text overwrites old text.
/EXENAME=exename Specifies the executable.
/MACROFILE=filename Specifies a file of macros to install.
macroname Specifies a name for a macro you create.
text Specifies commands you want to record.
UP and DOWN ARROWS recall commands; ESC clears command line; F7 displays
command history; ALT+F7 clears command history; F8 searches command
history; F9 selects a command by number; ALT+F10 clears macro definitions.
The following are some special codes in Doskey macro definitions:
$T Command separator. Allows multiple commands in a macro.
$1-$9 Batch parameters. Equivalent to %1-%9 in batch programs.
$* Symbol replaced by everything following macro name on command line.
* * * * * * *
DRIVERQUERY [/S system [/U username [/P [password]]]]
[/FO format] [/NH] [/SI] [/V]
描述:
允许管理员显示已安装设备驱动程序
的列表。
参数列表:
/S system 指定要连接到的远程系统。
/U [domain"]user 执行命令执行的用户上下文。
/P [password] 指定所给用户上下文的密码。
/FO format 指定要显示的结果类型。与命令行开关一起传递
的有效值是 "TABLE"、"LIST"、" CSV"。
/NH 指定“列标题”不应该在屏幕输出中
出现。只对 "TABLE" 和 "CSV" 格式有效。
/SI 提供有关已签名驱动程序的信息。
/V 显示详细任务输出。对签名的驱动程序无效。
/? 显示该帮助消息。
例如:
DRIVERQUERY
DRIVERQUERY /FO CSV /SI
DRIVERQUERY /NH
DRIVERQUERY /S ipaddress /U user /V
DRIVERQUERY /S system /U domain"user /P password /FO LIST
DRIVERQUERY [/S system [/U username [/P [password]]]]
[/FO format] [/NH] [/SI] [/V]
Description:
Enables an administrator to display a list of
installed device drivers.
Parameter List:
/S system Specifies the remote system to connect to.
/U [domain"]user Specifies the user context
under which the command should execute.
/P [password] Specify the password for the given
user context.
/FO format Specifies the type of output to display.
Valid values to be passed with the
switch are "TABLE", "LIST", "CSV".
/NH Specifies that the "Column Header"
should not be displayed. Valid for
"TABLE" and "CSV" format only.
/SI Provides information about signed drivers.
/V Displays verbose output. Not valid
for signed drivers.
/? Displays this help message.
Examples:
DRIVERQUERY
DRIVERQUERY /FO CSV /SI
DRIVERQUERY /NH
DRIVERQUERY /S ipaddress /U user /V
DRIVERQUERY /S system /U domain"user /P password /FO LIST
* * * * * * *
显示信息,或将命令回显打开或关上。
ECHO [ON | OFF]
ECHO [message]
要显示当前回显设置,键入不带参数的 ECHO。
Displays messages, or turns command-echoing on or off.
ECHO [ON | OFF]
ECHO [message]
Type ECHO without parameters to display the current echo setting.
* * * * * * *
结束批处理文件中环境改动的本地化操作。在执行ENDLOCAL 之后
所做的环境改动不再仅限于批处理文件。批处理文件结束后,
原先的设置无法还原。
ENDLOCAL
如果命令扩展被启用,ENDLOCAL 会如下改变:
如果相应的 SETLOCAL 用新的 ENABLEEXTENSIONS 或
DISABLEEXTENSIONS 选项启用或停用了命令扩展,那么,在
ENDLOCAL 之后,命令扩展的启用/停用状态会还原到执行
相应的 SETLOCAL 命令前的状态。
Ends localization of environment changes in a batch file.
Environment changes made after ENDLOCAL has been issued are
not local to the batch file; the previous settings are not
restored on termination of the batch file.
ENDLOCAL
If Command Extensions are enabled ENDLOCAL changes as follows:
If the corresponding SETLOCAL enable or disabled command extensions
using the new ENABLEEXTENSIONS or DISABLEEXTENSIONS options, then
after the ENDLOCAL, the enabled/disabled state of command extensions
will be restored to what it was prior to the matching SETLOCAL
command execution.
* * * * * * *
删除一个或数个文件。
DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
ERASE [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
names 指定一个或多个文件或者目录列表。
通配符可用来删除多个文件。
如果指定了一个目录,该目录中的所
有文件都会被删除。
/P 删除每一个文件之前提示确认。
/F 强制删除只读文件。
/S 删除所有子目录中的指定的文件。
/Q 安静模式。删除全局通配符时,不要求确认
/A 根据属性选择要删除的文件
属性 R 只读文件 S 系统文件
H 隐藏文件 A 存档文件
I 无内容索引文件 L 重分析点
- 表示“否”的前缀
如果命令扩展被启用,DEL 和 ERASE 更改如下:
/S 开关的显示句法会颠倒,即只显示已经
删除的文件,而不显示找不到的文件。
Deletes one or more files.
DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
ERASE [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
names Specifies a list of one or more files or directories.
Wildcards may be used to delete multiple files. If a
directory is specified, all files within the directory
will be deleted.
/P Prompts for confirmation before deleting each file.
/F Force deleting of read-only files.
/S Delete specified files from all subdirectories.
/Q Quiet mode, do not ask if ok to delete on global wildcard
/A Selects files to delete based on attributes
attributes R Read-only files S System files
H Hidden files A Files ready for archiving
I Not content indexed Files L Reparse Points
- Prefix meaning not
If Command Extensions are enabled DEL and ERASE change as follows:
The display semantics of the /S switch are reversed in that it shows
you only the files that are deleted, not the ones it could not find.
* * * * * * *
退出 CMD.EXE 程序(命令解释器)或当前批处理脚本。
EXIT [/B] [exitCode]
/B 指定要退出当前批处理脚本而不是 CMD.EXE。如果从一个
批处理脚本外执行,则会退出 CMD.EXE
exitCode 指定一个数字号码。如果指定了 /B,将 ERRORLEVEL
设成那个数字。如果退出 CMD.EXE,则用那个数字设置
过程退出代码。
Quits the CMD.EXE program (command interpreter) or the current batch
script.
EXIT [/B] [exitCode]
/B specifies to exit the current batch script instead of
CMD.EXE. If executed from outside a batch script, it
will quit CMD.EXE
exitCode specifies a numeric number. if /B is specified, sets
ERRORLEVEL that number. If quitting CMD.EXE, sets the process
exit code with that number.
* * * * * * *
比较两个文件或两个文件集并显示它们之间的不同
FC [/A] [/C] [/L] [/LBn] [/N] [/OFF[LINE]] [/T] [/U] [/W] [/nnnn]
[drive1:][path1]filename1 [drive2:][path2]filename2
FC /B [drive1:][path1]filename1 [drive2:][path2]filename2
/A 只显示每个不同处的第一行和最后一行。
/B 执行二进制比较。
/C 不分大小写。
/L 将文件作为 ASCII 文字比较。
/LBn 将连续不匹配的最大值设为指定的行数。
/N 在 ASCII 比较上显示行数。
/OFF[LINE] 不要跳过带有脱机属性集的文件。
/T 不要将 tab 扩充到空格。
/U 将文件作为 UNICODE 文字文件比较。
/W 为了比较而压缩空白(tab 和空格)。
/nnnn 指定不匹配处后必须连续匹配的行数。
[drive1:][path1]filename1
指定要比较的第一个文件或第一个文件集。
[drive2:][path2]filename2
指定要比较的第二个文件或第二个文件集。
Compares two files or sets of files and displays the differences between
them
FC [/A] [/C] [/L] [/LBn] [/N] [/OFF[LINE]] [/T] [/U] [/W] [/nnnn]
[drive1:][path1]filename1 [drive2:][path2]filename2
FC /B [drive1:][path1]filename1 [drive2:][path2]filename2
/A Displays only first and last lines for each set of differences.
/B Performs a binary comparison.
/C Disregards the case of letters.
/L Compares files as ASCII text.
/LBn Sets the maximum consecutive mismatches to the specified
number of lines.
/N Displays the line numbers on an ASCII comparison.
/OFF[LINE] Do not skip files with offline attribute set.
/T Does not expand tabs to spaces.
/U Compare files as UNICODE text files.
/W Compresses white space (tabs and spaces) for comparison.
/nnnn Specifies the number of consecutive lines that must match
after a mismatch.
[drive1:][path1]filename1
Specifies the first file or set of files to compare.
[drive2:][path2]filename2
Specifies the second file or set of files to compare.
* * * * * * *
在文件中搜索字符串。
FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]
/V 显示所有未包含指定字符串的行。
/C 仅显示包含字符串的行数。
/N 显示行号。
/I 搜索字符串时忽略大小写。
/OFF[LINE] 不要跳过具有脱机属性集的文件。
"string" 指定要搜索的文字串。
[drive:][path]filename
指定要搜索的文件。
如果没有指定路径,FIND 将搜索键入的或者由另一命令产生的文字。
Searches for a text string in a file or files.
FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]
/V Displays all lines NOT containing the specified string.
/C Displays only the count of lines containing the string.
/N Displays line numbers with the displayed lines.
/I Ignores the case of characters when searching for the string.
/OFF[LINE] Do not skip files with offline attribute set.
"string" Specifies the text string to find.
[drive:][path]filename
Specifies a file or files to search.
If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.
* * * * * * *
在文件中寻找字符串。
FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/F:file]
[/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]]
strings [[drive:][path]filename[ ...]]
/B 在一行的开始配对模式。
/E 在一行的结尾配对模式。
/L 按字使用搜索字符串。
/R 将搜索字符串作为一般表达式使用。
/S 在当前目录和所有子目录中搜索匹配文件。
/I 指定搜索不分大小写。
/X 打印完全匹配的行。
/V 只打印不包含匹配的行。
/N 在匹配的每行前打印行数。
/M 如果文件含有匹配项,只打印其文件名。
/O 在每个匹配行前打印字符偏移量。
/P 忽略有不可打印字符的文件。
/OFF[LINE] 不跳过带有脱机属性集的文件。
/A:attr 指定有十六进位数字的颜色属性。请见 "color /?"
/F:file 从指定文件读文件列表 (/ 代表控制台)。
/C:string 使用指定字符串作为文字搜索字符串。
/G:file 从指定的文件获得搜索字符串。 (/ 代表控制台)。
/D:dir 查找以分号为分隔符的目录列表
strings 要查找的文字。
[drive:][path]filename
指定要查找的文件。
除非参数有 /C 前缀,请使用空格隔开搜索字符串。
例如: 'FINDSTR "hello there" x.y' 在文件 x.y 中寻找 "hello" 或
"there"。'FINDSTR /C:"hello there" x.y' 文件 x.y 寻找
"hello there"。
一般表达式的快速参考:
. 通配符: 任何字符
* 重复: 以前字符或类别出现零或零以上次数
^ 行位置: 行的开始
$ 行位置: 行的终点
[class] 字符类别: 任何在字符集中的字符
[^class] 补字符类别: 任何不在字符集中的字符
[x-y] 范围: 在指定范围内的任何字符
"x Escape: 元字符 x 的文字用法
" 字位置: 字的结束
有关 FINDSTR 常见表达法的详细情况,请见联机命令参考。
Searches for strings in files.
FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file]
[/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]]
strings [[drive:][path]filename[ ...]]
/B Matches pattern if at the beginning of a line.
/E Matches pattern if at the end of a line.
/L Uses search strings literally.
/R Uses search strings as regular expressions.
/S Searches for matching files in the current directory and all
subdirectories.
/I Specifies that the search is not to be case-sensitive.
/X Prints lines that match exactly.
/V Prints only lines that do not contain a match.
/N Prints the line number before each line that matches.
/M Prints only the filename if a file contains a match.
/O Prints character offset before each matching line.
/P Skip files with non-printable characters.
/OFF[LINE] Do not skip files with offline attribute set.
/A:attr Specifies color attribute with two hex digits. See "color /?"
/F:file Reads file list from the specified file(/ stands for console).
/C:string Uses specified string as a literal search string.
/G:file Gets search strings from the specified file(/ stands for console).
/D:dir Search a semicolon delimited list of directories
strings Text to be searched for.
[drive:][path]filename
Specifies a file or files to search.
Use spaces to separate multiple search strings unless the argument is prefixed
with /C. For example, 'FINDSTR "hello there" x.y' searches for "hello" or
"there" in file x.y. 'FINDSTR /C:"hello there" x.y' searches for
"hello there" in file x.y.
Regular expression quick reference:
. Wildcard: any character
* Repeat: zero or more occurrences of previous character or class
^ Line position: beginning of line
$ Line position: end of line
[class] Character class: any one character in set
[^class] Inverse class: any one character not in set
[x-y] Range: any characters within the specified range
"x Escape: literal use of metacharacter x
" Word position: end of word
For full information on FINDSTR regular expressions refer to the online Command
Reference.
* * * * * * *
对一组文件中的每一个文件执行某个特定命令。
FOR %variable IN (set) DO command [command-parameters]
%variable 指定一个单一字母可替换的参数。
(set) 指定一个或一组文件。可以使用通配符。
command 指定对每个文件执行的命令。
command-parameters
为特定命令指定参数或命令行开关。
在批处理程序中使用 FOR 命令时,指定变量请使用 %%variable
而不要用 %variable。变量名称是区分大小写的,所以 %i 不同于 %I.
如果命令扩展被启用,下列额外的 FOR 命令格式会受到
支持:
FOR /D %variable IN (set) DO command [command-parameters]
如果集中包含通配符,则指定与目录名匹配,而不与文件
名匹配。
FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]
检查以 [drive:]path 为根的目录树,指向每个目录中的
FOR 语句。如果在 /R 后没有指定目录,则使用当前
目录。如果集仅为一个单点(.)字符,则枚举该目录树。
FOR /L %variable IN (start,step,end) DO command [command-parameters]
该集表示以增量形式从开始到结束的一个数字序列。
因此,(1,1,5) 将产生序列 1 2 3 4 5,(5,-1,1) 将产生
序列 (5 4 3 2 1)。
FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]
或者,如果有 usebackq 选项:
FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]
filenameset 为一个或多个文件名。继续到 filenameset 中的
下一个文件之前,每份文件都已被打开、读取并经过处理。
处理包括读取文件,将其分成一行行的文字,然后将每行
解析成零或更多的符号。然后用已找到的符号字符串变量值
调用 For 循环。以默认方式,/F 通过每个文件的每一行中分开
的第一个空白符号。跳过空白行。您可通过指定可选 "options"
参数替代默认解析操作。这个带引号的字符串包括一个或多个
指定不同解析选项的关键字。这些关键字为:
eol=c - 指一个行注释字符的结尾(就一个)
skip=n - 指在文件开始时忽略的行数。
delims=xxx - 指分隔符集。这个替换了空格和跳格键的
默认分隔符集。
tokens=x,y,m-n - 指每行的哪一个符号被传递到每个迭代
的 for 本身。这会导致额外变量名称的分配。m-n
格式为一个范围。通过 nth 符号指定 mth。如果
符号字符串中的最后一个字符星号,
那么额外的变量将在最后一个符号解析之后
分配并接受行的保留文本。
usebackq - 指定新语法已在下类情况中使用:
在作为命令执行一个后引号的字符串并且一个单
引号字符为文字字符串命令并允许在 filenameset
中使用双引号扩起文件名称。
某些范例可能有助:
FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i %j %k
会分析 myfile.txt 中的每一行,忽略以分号打头的那些行,将
每行中的第二个和第三个符号传递给 for 函数体,用逗号和/或
空格分隔符号。请注意,此 for 函数体的语句引用 %i 来
获得第二个符号,引用 %j 来获得第三个符号,引用 %k
来获得第三个符号后的所有剩余符号。对于带有空格的文件
名,您需要用双引号将文件名括起来。为了用这种方式来使
用双引号,还需要使用 usebackq 选项,否则,双引号会
被理解成是用作定义某个要分析的字符串的。
%i 在 for 语句中显式声明,%j 和 %k 是通过
tokens= 选项隐式声明的。可以通过 tokens= 一行
指定最多 26 个符号,只要不试图声明一个高于字母 "z" 或
"Z" 的变量。请记住,FOR 变量是单一字母、分大小写和全局的变量;
而且,不能同时使用超过 52 个。
还可以在相邻字符串上使用 FOR /F 分析逻辑,方法是,
用单引号将括号之间的 filenameset 括起来。这样,该字符
串会被当作一个文件中的一个单一输入行进行解析。
最后,可以用 FOR /F 命令来分析命令的输出。方法是,将
括号之间的 filenameset 变成一个反括字符串。该字符串会
被当作命令行,传递到一个子 CMD.EXE,其输出会被捕获到
内存中,并被当作文件分析。如以下例子所示:
FOR /F "usebackq delims==" %i IN (`set`) DO @echo %i
会枚举当前环境中的环境变量名称。
另外,FOR 变量参照的替换已被增强。您现在可以使用下列
选项语法:
%~I - 删除任何引号("),扩展 %I
%~fI - 将 %I 扩展到一个完全合格的路径名
%~dI - 仅将 %I 扩展到一个驱动器号
%~pI - 仅将 %I 扩展到一个路径
%~nI - 仅将 %I 扩展到一个文件名
%~xI - 仅将 %I 扩展到一个文件扩展名
%~sI - 扩展的路径只含有短名
%~aI - 将 %I 扩展到文件的文件属性
%~tI - 将 %I 扩展到文件的日期/时间
%~zI - 将 %I 扩展到文件的大小
%~$PATH:I - 查找列在路径环境变量的目录,并将 %I 扩展
到找到的第一个完全合格的名称。如果环境变量名
未被定义,或者没有找到文件,此组合键会扩展到
空字符串
可以组合修饰符来得到多重结果:
%~dpI - 仅将 %I 扩展到一个驱动器号和路径
%~nxI - 仅将 %I 扩展到一个文件名和扩展名
%~fsI - 仅将 %I 扩展到一个带有短名的完整路径名
%~dp$PATH:I - 搜索列在路径环境变量的目录,并将 %I 扩展
到找到的第一个驱动器号和路径。
%~ftzaI - 将 %I 扩展到类似输出线路的 DIR
在以上例子中,%I 和 PATH 可用其他有效数值代替。%~ 语法
用一个有效的 FOR 变量名终止。选取类似 %I 的大写变量名
比较易读,而且避免与不分大小写的组合键混淆。
Runs a specified command for each file in a set of files.
FOR %variable IN (set) DO command [command-parameters]
%variable Specifies a single letter replaceable parameter.
(set) Specifies a set of one or more files. Wildcards may be used.
command Specifies the command to carry out for each file.
command-parameters
Specifies parameters or switches for the specified command.
To use the FOR command in a batch program, specify %%variable instead
of %variable. Variable names are case sensitive, so %i is different
from %I.
If Command Extensions are enabled, the following additional
forms of the FOR command are supported:
FOR /D %variable IN (set) DO command [command-parameters]
If set contains wildcards, then specifies to match against directory
names instead of file names.
FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]
Walks the directory tree rooted at [drive:]path, executing the FOR
statement in each directory of the tree. If no directory
specification is specified after /R then the current directory is
assumed. If set is just a single period (.) character then it
will just enumerate the directory tree.
FOR /L %variable IN (start,step,end) DO command [command-parameters]
The set is a sequence of numbers from start to end, by step amount.
So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would
generate the sequence (5 4 3 2 1)
FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]
or, if usebackq option present:
FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ('string') DO command [command-parameters]
FOR /F ["options"] %variable IN (`command`) DO command [command-parameters]
filenameset is one or more file names. Each file is opened, read
and processed before going on to the next file in filenameset.
Processing consists of reading in the file, breaking it up into
individual lines of text and then parsing each line into zero or
more tokens. The body of the for loop is then called with the
variable value(s) set to the found token string(s). By default, /F
passes the first blank separated token from each line of each file.
Blank lines are skipped. You can override the default parsing
behavior by specifying the optional "options" parameter. This
is a quoted string which contains one or more keywords to specify
different parsing options. The keywords are:
eol=c - specifies an end of line comment character
(just one)
skip=n - specifies the number of lines to skip at the
beginning of the file.
delims=xxx - specifies a delimiter set. This replaces the
default delimiter set of space and tab.
tokens=x,y,m-n - specifies which tokens from each line are to
be passed to the for body for each iteration.
This will cause additional variable names to
be allocated. The m-n form is a range,
specifying the mth through the nth tokens. If
the last character in the tokens= string is an
asterisk, then an additional variable is
allocated and receives the remaining text on
the line after the last token parsed.
usebackq - specifies that the new semantics are in force,
where a back quoted string is executed as a
command and a single quoted string is a
literal string command and allows the use of
double quotes to quote file names in
filenameset.
Some examples might help:
FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i %j %k
would parse each line in myfile.txt, ignoring lines that begin with
a semicolon, passing the 2nd and 3rd token from each line to the for
body, with tokens delimited by commas and/or spaces. Notice the for
body statements reference %i to get the 2nd token, %j to get the
3rd token, and %k to get all remaining tokens after the 3rd. For
file names that contain spaces, you need to quote the filenames with
double quotes. In order to use double quotes in this manner, you also
need to use the usebackq option, otherwise the double quotes will be
interpreted as defining a literal string to parse.
%i is explicitly declared in the for statement and the %j and %k
are implicitly declared via the tokens= option. You can specify up
to 26 tokens via the tokens= line, provided it does not cause an
attempt to declare a variable higher than the letter 'z' or 'Z'.
Remember, FOR variables are single-letter, case sensitive, global,
and you can't have more than 52 total active at any one time.
You can also use the FOR /F parsing logic on an immediate string, by
making the filenameset between the parenthesis a quoted string,
using single quote characters. It will be treated as a single line
of input from a file and parsed.
Finally, you can use the FOR /F command to parse the output of a
command. You do this by making the filenameset between the
parenthesis a back quoted string. It will be treated as a command
line, which is passed to a child CMD.EXE and the output is captured
into memory and parsed as if it was a file. So the following
example:
FOR /F "usebackq delims==" %i IN (`set`) DO @echo %i
would enumerate the environment variable names in the current
environment.
In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:
%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string
The modifiers can be combined to get compound results:
%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line
In the above examples %I and PATH can be replaced by other valid
values. The %~ syntax is terminated by a valid FOR variable name.
Picking upper case variable names like %I makes it more readable and
avoids confusion with the modifiers, which are not case sensitive.
* * * * * * *
格式化磁盘以供 Windows 使用。
FORMAT volume [/FS:file-system] [/V:label] [/Q] [/A:size] [/C] [/X] [/P:passes]
FORMAT volume [/V:label] [/Q] [/F:size] [/P:passes]
FORMAT volume [/V:label] [/Q] [/T:tracks /N:sectors] [/P:passes]
FORMAT volume [/V:label] [/Q] [/P:passes]
FORMAT volume [/Q]
volume 指定驱动器号(后面跟一个冒号)、
装入点或卷名。
/FS:filesystem 指定文件系统类型(FAT、FAT32、NTFS、
或 UDF)。
/V:label 指定卷标。
/Q 执行快速格式化。请注意该开关可覆盖 /P。
/C 仅适于 NTFS: 默认情况下,将压缩在该新建卷上创建的
文件。
/X 如果必要,先强制卸下卷。那时,该卷所有已打开的句柄
不再有效。
/R:revision 仅 UDF: 强制格式化为特定的 UDF 版本
(1.02、1.50、2.00、2.01、2.50)。默认
修订版为 2.01。
/D 仅适用于 UDF 2.50: 将复制元数据。
/A:size 替代默认分配单位大小。极力建议您在一般状况下使用默认
设置。
NTFS 支持 512、1024、2048、4096、8192、16K、32K、64K。
FAT 支持 512、1024、2048、4096、8192、16K、32K、64k,
(128k、256k 用于大于 512 字节的扇区)。
FAT32 支持 512、1024、2048、4096、8192、16k、32k、64k,
(128k 、256k 用于大于 512 字节的扇区)。
注意: FAT 及 FAT32 文件系统对卷上的群集数量有以下限制:
FAT: 群集数量 <= 65526
FAT32: 65526 < 群集数量 < 4177918
如果判定使用指定的群集大小无法满足以上需求,格式化将立即停止。
NTFS 压缩不支持大于 4096 的分配单元大小。
/F:size 指定要格式化的软盘大小(1.44)
/T:tracks 为磁盘指定每面磁道数。
/N:sectors 指定每条磁道的扇区数。
/P:passes 将卷上每个扇区的操作次数清零。
此参数对 /Q 无效
Formats a disk for use with Windows.
FORMAT volume [/FS:file-system] [/V:label] [/Q] [/A:size] [/C] [/X] [/P:passes]
FORMAT volume [/V:label] [/Q] [/F:size] [/P:passes]
FORMAT volume [/V:label] [/Q] [/T:tracks /N:sectors] [/P:passes]
FORMAT volume [/V:label] [/Q] [/P:passes]
FORMAT volume [/Q]
volume Specifies the drive letter (followed by a colon),
mount point, or volume name.
/FS:filesystem Specifies the type of the file system (FAT, FAT32, NTFS,
or UDF).
/V:label Specifies the volume label.
/Q Performs a quick format. Note that this switch overrides /P.
/C NTFS only: Files created on the new volume will be compressed
by default.
/X Forces the volume to dismount first if necessary. All opened
handles to the volume would no longer be valid.
/R:revision UDF only: Forces the format to a specific UDF version
(1.02, 1.50, 2.00, 2.01, 2.50). The default
revision is 2.01.
/D UDF 2.50 only: Metadata will be duplicated.
/A:size Overrides the default allocation unit size. Default settings
are strongly recommended for general use.
NTFS supports 512, 1024, 2048, 4096, 8192, 16K, 32K, 64K.
FAT supports 512, 1024, 2048, 4096, 8192, 16K, 32K, 64K,
(128K, 256K for sector size > 512 bytes).
FAT32 supports 512, 1024, 2048, 4096, 8192, 16K, 32K, 64K,
(128K, 256K for sector size > 512 bytes).
Note that the FAT and FAT32 files systems impose the
following restrictions on the number of clusters on a volume:
FAT: Number of clusters <= 65526
FAT32: 65526 < Number of clusters < 4177918
Format will immediately stop processing if it decides that
the above requirements cannot be met using the specified
cluster size.
NTFS compression is not supported for allocation unit sizes
above 4096.
/F:size Specifies the size of the floppy disk to format (1.44)
/T:tracks Specifies the number of tracks per disk side.
/N:sectors Specifies the number of sectors per track.
/P:passes Zero every sector on the volume passes times. This switch is
not valid with /Q