Windows provides different system management modes like interactive and batch. Batch management mode is used like running scripts without or little user interaction.
Windows提供了不同的系统管理模式,例如交互式和批处理。 批处理管理模式的使用类似于运行脚本,而无需用户交互或用户交互很少。
批处理文件和扩展名 (Batch File and Extension)
Batch files are text files which contains MSDOS and Windows commands and tools. Batch files generally uses bat
or cmd
extensions.But other extensions can be used as long as they will run as batch file with cmd.exe
.We can run a batch file without extension or different extension with cmd.exe
. In this example we will run a batch file named mybatchfile.txt
批处理文件是包含MSDOS和Windows命令和工具的文本文件。 批处理文件一般采用bat
或cmd
extensions.But其他扩展可以,只要他们将运行与批处理文件中使用cmd.exe
。我们可以运行不带扩展名或不同的扩展名与批处理文件cmd.exe
。 在此示例中,我们将运行一个名为mybatchfile.txt
的批处理文件。
$ cmd.exe mybatchfile.txt
ASSOC –关联文件类型 (ASSOC – Associate File Type)
We can use ASSOC
command in order to find a file type and detailed explanation with this command. We will provide the extension like .txt
into the ASSOC
command like below.
我们可以使用ASSOC
命令来查找文件类型和此命令的详细说明。 我们将在以下的ASSOC
命令中提供.txt
之类的扩展名。
ASSOC ".exe"
![ASSOC - Associate File Type](https://img-blog.csdnimg.cn/img_convert/f567a80163bb5c2cb37a2b2ed53b0283.png)
As we can see from output that .exe
extension is associated with executable file .
从输出中可以看到, .exe
扩展名与可执行文件相关联。
If we do not provide a parameter ASSOC
will list all existing associations with related extensions.
如果我们不提供参数,则ASSOC
将列出所有具有相关扩展名的现有关联。
ASSOC
![](https://img-blog.csdnimg.cn/img_convert/70d4616fb6717612881cf2d58f57e384.png)
ATTRIB-列表文件属性 (ATTRIB- List File Attributes)
ATTRIB
command is used to list, display and change file attributes about files, folders and directories.
ATTRIB
命令用于列出,显示和更改有关文件,文件夹和目录的文件属性。
列表属性 (List Attributes)
We can list given file or folder attributes like below.
我们可以像下面列出给定的文件或文件夹属性。
attrib msdia80.dll
![List Attributes](https://img-blog.csdnimg.cn/img_convert/f2929a668592326ed23c832d6fc584d5.png)
更改为只读(Change To Read Only)
We can change the file attribute to read only which will made given file uneditable.
我们可以将文件属性更改为只读,这会使给定的文件不可编辑。
attrib +r msdia80.dll
隐藏 (Make Hidden)
If we want to make to hidden the file we will use +ah
option. This will made file hidden from regular user files and folders.
如果我们想隐藏文件,我们将使用+ah
选项。 这将使文件从常规用户文件和文件夹中隐藏。
attrib +ah msdia80.dll
删除只读属性 (Remove Read Only Attribute)
After setting some attributed we can remote these attributes later. We will use -
sign to remove specified attribute. In this example we will remove read only attribute with the -r
option like below.
设置一些属性后,我们可以在以后远程访问这些属性。 我们将使用-
符号删除指定的属性。 在此示例中,我们将使用-r
选项删除只读属性,如下所示。
attrib -r msdia80.dll
CD –更改当前工作目录 (CD – Change Current Working Directory)
CD
will provide very useful feature where we can change given working directory. We can also provide multi level paths to change.
CD
将提供非常有用的功能,我们可以在其中更改给定的工作目录。 我们还可以提供多级更改路径。
更改为给定的子目录 (Change To Given Child Directory)
We will start by changing given child directory. We will first use DIR
to list directories.
我们将从更改给定的子目录开始。 我们将首先使用DIR
列出目录。
cd Users
![Change To Given Child Directory](https://img-blog.csdnimg.cn/img_convert/1a1fee5d6edaa49638393e0b423a89f2.png)
转到父目录(Change To Parent Directory)
We can use ..
as specify parent directory. We can go upper level directory or parent directory with the following command.
我们可以使用..
作为指定父目录。 我们可以使用以下命令进入上一级目录或上级目录。
cd ..
更改驱动器或分区 (Change Drive or Partition)
We can also change the current partition. We will change to the drive :d
in this example.
我们还可以更改当前分区。 在本示例中,我们将更改为drive :d
。
cd d:
CHKDSK –检查磁盘和文件系统一致性 (CHKDSK – Check Disk and File System Consistency)
CHKDSK
command can be used to check and repair disk and file systems. We can simply use it like below.
CHKDSK
命令可用于检查和修复磁盘和文件系统。 我们可以像下面这样简单地使用它。
chkdsk
Windows Chkdsk Utility Tutorial with Examples To Fix File System Errors
Windows Chkdsk实用程序教程,带有修复文件系统错误的示例
CHOICE – Provide List Of Options
选择–提供选项列表
If we need to get input from the user with provided choice we can use CHOICE
command like below. We will provide Yes or No like below.
如果需要使用提供的选项从用户那里获取输入,则可以使用如下所示的CHOICE
命令。 我们将提供“是”或“否”,如下所示。
ECHO You want tea?
CHOISE /c YN /m "Yes or No"
CLS-清除屏幕 (CLS- Clear The Screen)
After some work and operation there will be a lot of option on the console or screen. We can clean this console or screen with the CLS
command.
经过一些工作和操作后,控制台或屏幕上将有很多选项。 我们可以使用CLS
命令清理此控制台或屏幕。
CLS
CMD –调用新命令提示符 (CMD – Invoke New Command Prompt)
If we want to create new or child command prompt we can use CMD
which will call cmd.exe
application.
如果要创建新命令或子命令提示符,可以使用CMD
来调用cmd.exe
应用程序。
CMD
COMP –比较两个文件大小 (COMP – Compare Two Files Sizes)
If we have some some files and we want to compare their sizes we can use COMP
command. We will provide two paramers those will be the file names. In this example we will compare files named a.txt
and b.txt
如果我们有一些文件,并且想比较它们的大小,可以使用COMP
命令。 我们将提供两个参数,它们将是文件名。 在此示例中,我们将比较名为a.txt
和b.txt
文件
COMP a.txt b.txt
转换–转换文件系统类型 (CONVERT – Convert File System Type)
This is a bit low level command where we can convert file system of the given partition. In this example we will convert partition D:
.
这是一个有点低级的命令,我们可以在其中转换给定分区的文件系统。 在此示例中,我们将转换分区D:
CONVERT D:\
COPY –复制文件 (COPY – Copy Files)
We can copy given file to the destination with the COPY
command. In this example we will copy file a.txt
to the D:
partition.
我们可以使用COPY
命令将给定文件复制到目标位置。 在此示例中,我们将文件a.txt
复制到D:
分区。
COPY c:\a.txt d:\
DATE –显示当前日期 (DATE – Display Current Date)
We can use %DATE%
variable which holds the current date. We will print to the console with the echo
command.
我们可以使用%DATE%
变量来保存当前日期。 我们将使用echo
命令打印到控制台。
echo %DATE%
![DATE - Display Current Date](https://img-blog.csdnimg.cn/img_convert/70c3b907c902cdbed6298f12a5730f3f.png)
DEL –删除文件(DEL – Delete Files)
We can delete files with the DEL
command. We will provide the name of the file we want to delete.
我们可以使用DEL
命令删除文件。 我们将提供我们要删除的文件的名称。
删除给定文件 (Delete Given File)
We will delete file named a.txt
我们将删除名为a.txt
文件
DEL a.txt
删除给定扩展名 (Delete Given Extension)
We can also delete for specific extension. For example we can delete text files those generally have .txt
extension with the following command.
我们也可以删除特定扩展名。 例如,我们可以使用以下命令删除扩展名通常为.txt
文本文件。
DEL *.txt
删除文件前询问 (Ask Before Delete File)
If we will delete in bulk confirmation will help us. We can use /p
option which will enable confirmation before each file deletion.
如果我们将批量删除,确认将对我们有帮助。 我们可以使用/p
选项,该选项将在每个文件删除之前启用确认。
DEL /p *.txt
DIR –列出文件和文件夹 (DIR – List File and Folders)
We can list current working and given directory files and folders with the DIR
command like below.
我们可以使用DIR
命令列出当前工作目录和给定目录文件和文件夹,如下所示。
列出所有文件和文件夹 (List All Files and Folders)
We can use DIR
without any option to list all files and folders for the current working directory
我们可以不带任何选项使用DIR
列出当前工作目录的所有文件和文件夹
DIR
![List All Files and Folders](https://img-blog.csdnimg.cn/img_convert/e8d1715bb561c2f4ddfde698e42e23c3.png)
列出隐藏的文件和文件夹(List Hidden Files and Folders)
By default hidden files and folders do not listed. But we can list hidden files and folders with the /ah
option like below.
默认情况下,未列出隐藏的文件和文件夹。 但是我们可以使用/ah
选项列出隐藏的文件和文件夹,如下所示。
DIR /ah
![List Hidden Files and Folders](https://img-blog.csdnimg.cn/img_convert/41dad31d479daa1601becd94a7e2afe0.png)
列出特定的扩展文件(List Specific Extension Files)
We can list specific extension by providing the extension to the DIR
command. In this example we will list extension with *.php
我们可以通过提供DIR
命令的扩展名来列出特定的扩展名。 在此示例中,我们将列出带有*.php
扩展名
dir "*.php"
DISKPART –显示和更改磁盘分区和属性 (DISKPART – Show and Change Disk Partition and Properties)
We can use DISKPART
command in order to list, display and change disk partition properties.
我们可以使用DISKPART
命令来列出,显示和更改磁盘分区属性。
DISKPART
Windows Diskpart Command Tutorial with Examples To Format Disk
Windows Diskpart命令教程,包括格式化磁盘的示例
DRIVERQUERY –列出驱动程序和属性(DRIVERQUERY – List Drivers and Properties)
We can use DRIVERQUERY
in order to list installed device drivers and related properties with dates.
我们可以使用DRIVERQUERY
来列出已安装的设备驱动程序和相关属性以及日期。
DRIVERQUERY
![DRIVERQUERY - List Drivers and Properties](https://img-blog.csdnimg.cn/img_convert/97e045d163063e6df6bb987da1e81129.png)
ECHO –打印到控制台(ECHO – Print To The Console)
ECHO
command is used to print to the console or standard output. We can also use this command in order to print environment variables or given strings.
ECHO
命令用于打印到控制台或标准输出。 我们也可以使用此命令来打印环境变量或给定的字符串。
打印给定的字符串 (Print Given String)
We will print given string which is "Hello World"
in this case.
在这种情况下,我们将打印给定的字符串"Hello World"
。
ECHO "Hello World"
打印环境变量 (Print Environment Variable)
We can print given environment variable like %DATE%
in this case
在这种情况下,我们可以打印给定的环境变量,例如%DATE%
echo %DATE%
退出–终止并退出控制台 (EXIT – Terminate and Exit From Console)
We can use EXIT
in order to terminate current console and exit. This will also end current script too.
我们可以使用EXIT
来终止当前控制台并退出。 这也将结束当前脚本。
EXIT
FC –区分两个文件 (FC – Diff Two Files)
We can compare two files and print differencies with the FC
command. We will provide two files named a.txt
and b.txt
in this example.
我们可以比较两个文件并使用FC
命令打印差异。 在此示例中,我们将提供两个名为a.txt
和b.txt
文件。
FC a.txt b.txt
查找–在文件中搜索给定的字符串 (FIND – Search Given String In A File)
We can use FIND
command to search for given string in a given file. In this example we will search for test
in file named a.txt
.
我们可以使用FIND
命令在给定文件中搜索给定字符串。 在此示例中,我们将在名为a.txt
文件中搜索test
。
FIND "test" a.txt
格式-更改文件系统 (FORMAT – Change File System)
Another command to change File System is FORMAT
command. We will also provide the partition we want to format.
更改文件系统的另一个命令是FORMAT
命令。 我们还将提供要格式化的分区。
FORMAT F:\
帮助–显示帮助信息 (HELP – Display Help Information)
While using batch commands we may need to get help for general or specific command. We can use HELP
command which will display available commands provided by MSDOS.
使用批处理命令时,我们可能需要获得常规或特定命令的帮助。 我们可以使用HELP
命令,它将显示MSDOS提供的可用命令。
列出所有命令 (List All Command)
Without any option we can list all commands provided by MSDOS with HELP
command like below.
没有任何选择,我们可以列出MSDOS提供的所有命令以及如下的HELP
命令。
HELP
![List All Command](https://img-blog.csdnimg.cn/img_convert/182ad9f38f64fe21626e13bf09c64398.png)
帮助特定命令(Help For Specific Command)
We can get detailed information about a MSDOS command by providing the command after HELP. In this example we will list information about DIR
command.
通过在HELP之后提供命令,我们可以获得有关MSDOS命令的详细信息。 在此示例中,我们将列出有关DIR
命令的信息。
HELP dir
![Help For Specific Command](https://img-blog.csdnimg.cn/img_convert/dc0eff549e51604a53bcc6f69173c2af.png)
IPCONFIG –列出网络配置,如IP地址(IPCONFIG – List Network Configuration Like IP Address)
IPCONFIG
will list information about the current system network interfaces and IP configuration.
IPCONFIG
将列出有关当前系统网络接口和IP配置的信息。
IPCONFIG
![IPCONFIG - List Network Configuration Like IP Address](https://img-blog.csdnimg.cn/img_convert/5ffa86d4ea761976898804fe173b92f5.png)
Windows Ipconfig Command Tutorial With Examples To List, Change, Renew IP Configuration
Windows Ipconfig命令教程,包括列出,更改,续订IP配置的示例
标签–添加,设置或删除磁盘标签(LABEL – Add, Set or Remove Disk Labels)
Disks are labeled for easy of management. We can use LABEL
command in order to change or remove disk labels.
磁盘被标记为易于管理。 我们可以使用LABEL
命令来更改或删除磁盘标签。
LABEL D:\
![LABEL - Add, Set or Remove Disk Labels](https://img-blog.csdnimg.cn/img_convert/cb8dc9d1a72434f16a41fcc181c6163d.png)
MD –创建新目录(MD – Create New Directory)
We can use MD
command in order to create new directory or folder. In this example we will create a folder named BACKUP
.
我们可以使用MD
命令来创建新目录或文件夹。 在此示例中,我们将创建一个名为BACKUP
的文件夹。
MD BACKUP
更多–阅读文件内容 (MORE – Read File Contents)
We can read a file content with the MORE
command. Especially text files can be printed from command line. We will also provide the file name to this command.
我们可以使用MORE
命令读取文件内容。 特别是文本文件可以从命令行打印。 我们还将提供此命令的文件名。
MORE abc.txt
移动–移动文件和文件夹 (MOVE – Move Files and Folders)
We can use MOVE
command in order to move files and folders. This command can be also used to rename files and folders.
我们可以使用MOVE
命令来移动文件和文件夹。 此命令还可用于重命名文件和文件夹。
MOVE c:\abc.txt d:\xyz.txt
NET –管理Windows网络服务 (NET – Manage Windows Network Services)
Windows operating system provides a lot of network related options for their operating system and services. We can use NET
command with the following features.
Windows操作系统为其操作系统和服务提供了许多与网络相关的选项。 我们可以使用具有以下功能的NET
命令。
- net accounts 净账户
- net computer网络计算机
- net config网络配置
- net continue净继续
- net file网络文件
- net group网组
- net help网络帮助
- net name网名
- net pause净暂停
- net print净印刷
- net send净发送
- net session净会话
- net share净份额
- net start净启动
- net statistics净统计
- net stop净止损
- net time净时间
- net use净使用
- net view净视图
How To Use Net Use Command In Windows Command Line?
PATH –显示路径变量 (PATH – Display Path Variable)
PATH variable provides commands and applications to run. We can list these paths with the PATH
variable.
PATH变量提供要运行的命令和应用程序。 我们可以使用PATH
变量列出这些路径。
echo %PATH%
![PATH - Display Path Variable](https://img-blog.csdnimg.cn/img_convert/0034e36df169352126c26f0fcecdff74.png)
暂停–停止当前正在运行的脚本(PAUSE – Stop Current Running Script)
If we want to stop a script output we can use PAUSE
command. This will stop script up to pressing a key for the console.
如果要停止脚本输出,可以使用PAUSE
命令。 这将停止脚本,直到按控制台的键为止。
PAUSE
PING –测试远程主机 (PING – Test Remote Hosts)
PING
command can be used to test remote system connectivity. We will also provide the IP address or host name of the remote system. It will send 4 time and ICMP package for test.
PING
命令可用于测试远程系统连接。 我们还将提供远程系统的IP地址或主机名。 它将发送4时间和ICMP包进行测试。
PING google.com
![PING - Test Remote Hosts](https://img-blog.csdnimg.cn/img_convert/817c72cd12ad682e28205f6d706a9282.png)
RD –删除空目录(RD – Remove Empty Directories)
We can use RD
command in order to remove empty directory. This will not work for non-empty directories. We will remove directory named ABC
.
我们可以使用RD
命令来删除空目录。 这不适用于非空目录。 我们将删除名为ABC
目录。
RD ABC
REM –在批处理文件中添加注释 (REM – Add Comment To The Batch File)
We may need to put some comments about the script file. We will use REM
in order to add comments. All lines starting with the REM
will interpreted as comment.
我们可能需要对脚本文件添加一些注释。 我们将使用REM
来添加评论。 以REM
开头的所有行将被解释为注释。
REM This is a comment no command :)
REN –重命名文件和目录 (REN – Rename File and Directories)
We can rename files and directories with the REN
command. We will provide current name and new name. In this example we will rename file abc.txt
to the 123.txt
我们可以使用REN
命令重命名文件和目录。 我们将提供当前名称和新名称。 在此示例中,我们将文件abc.txt
重命名为123.txt
REN abc.txt 123.txt
SET –显示环境变量 (SET – Display Environment Variables)
We can list current environment variables with the SET
command.
我们可以使用SET
命令列出当前的环境变量。
SET
![SET - Display Environment Variables](https://img-blog.csdnimg.cn/img_convert/98ccd5f925f9471dc45cd465b55c60f9.png)
关机–关闭系统(SHUTDOWN – Shutdown the System)
We can shutdown the system with the SHUTDOWN
command like below.
我们可以使用SHUTDOWN
命令关闭系统,如下所示。
SHUTDOWN
SORT –对文件内容进行排序 (SORT – Sort Content Of A File)
We can sort given file content and print to the console with the SORT
command like below. In this example we will sort and print file named abc.txt
我们可以对给定的文件内容进行排序,并使用SORT
命令将其打印到控制台,如下所示。 在此示例中,我们将排序并打印名为abc.txt
文件
SORT abc.txt
开始–启动新程序 (START – Start New Program)
We can use START
command by providing and exe or a batch file to start. In this example we will start the application named notepad.exe
我们可以通过提供START
命令和exe或批处理文件来启动。 在此示例中,我们将启动名为notepad.exe
的应用程序
START notepad.exe
SYSTEMINFO –显示计算机和操作系统信息 (SYSTEMINFO – Display Computer and Operating System Information)
We can use SYSTEMINFO
in order to list and display computer, operating system and software information.
我们可以使用SYSTEMINFO
来列出和显示计算机,操作系统和软件信息。
SYSTEMINFO
![SYSTEMINFO - Display Computer and Operating System Information](https://img-blog.csdnimg.cn/img_convert/a25af6b9e8c05fc700eb3025ca70a78a.png)
How To Open System Information Panel On Windows To Check Computer and Specification?
任务杀死–杀死任务和过程 (TASKKILL – Kill Task and Process)
Processes can be killed in different ways. We can use TASKKILL
command in order to end given process. In this example we will ill task or process named notepad.exe
可以用不同的方式杀死进程。 我们可以使用TASKKILL
命令来结束给定的过程。 在此示例中,我们将使名为notepad.exe
任务或进程notepad.exe
TASKKILL /im notepad.exe
任务列表–列出当前任务或过程 (TASKLIST – List Current Tasks or Processes)
We can list currently running tasks and processes with the TASKLIST
command.
我们可以使用TASKLIST
命令列出当前正在运行的任务和流程。
TASKLIST
![TASKLIST - List Current Tasks or Processes](https://img-blog.csdnimg.cn/img_convert/24193d46622943b68fbd28b3722e1a30.png)
TIME –显示或设置当前时间(TIME – Display or Set Current Time)
We can use TIME
command in order to display or set current time of the system. We will use %TIME%
variable like below.
我们可以使用TIME
命令来显示或设置系统的当前时间。 我们将使用%TIME%
变量,如下所示。
echo %TIME%
![TIME - Display or Set Current Time](https://img-blog.csdnimg.cn/img_convert/4fe3c8a70bf1232dec972d71f4b9e804.png)
标题-设置MSDOS控制台的标题(TITLE – Set Title Of MSDOS Console)
We can set the title of the currently running MSDOS console with the TITLE
command. In this example we will set the console title as MYCONSOLE
我们可以使用TITLE
命令设置当前正在运行的MSDOS控制台的TITLE
。 在此示例中,我们将控制台标题设置为MYCONSOLE
TITLE MYCONSOLE
TREE –将子目录显示为树 (TREE – Display Subdirectories As Tree)
We can list current directory child or subdirectories with the TREE
command. It will provide very useful output for investigating folder hierarchy.
我们可以使用TREE
命令列出当前目录的子目录或子目录。 这将为调查文件夹层次结构提供非常有用的输出。
TREE
![TREE - Display Subdirectories As Tree](https://img-blog.csdnimg.cn/img_convert/1301b526b3870deb7f8b614e0c216383.png)
VER –显示Windows或MSDOS版本(VER – Display Windows or MSDOS Version)
Windows operating systems and MSDOS have different versions. We can display current operating system and MSDOS version with the VER
command like below.
Windows操作系统和MSDOS具有不同的版本。 我们可以使用VER
命令显示当前的操作系统和MSDOS版本,如下所示。
VER
![VER - Display Windows or MSDOS Version](https://img-blog.csdnimg.cn/img_convert/86b7534f99564a467f0f02b56f462dbd.png)
VOL –显示音量标签(VOL – Display Volume Label)
We can displat current volume label with the VOL
command.
我们可以使用VOL
命令显示当前的音量标签。
VOL
XCOPY –复制文件和文件夹 (XCOPY – Copy Files and Folders)
XCOPY
command can be used to copy files and folders. We will provide the source and destination files and folders. In this example file abc.txt
to the 123.txt
XCOPY
命令可用于复制文件和文件夹。 我们将提供源和目标文件和文件夹。 在此示例文件abc.txt
到123.txt
XCOPY abc.txt 123.txt
Windows Copy Operation With Xcopy Command Tutorial With Examples
翻译自: https://www.poftut.com/batch-file-commands-for-windows-msdos/