Windows MSDOS的批处理文件命令

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命令和工具的文本文件。 批处理文件一般采用batcmd 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
ASSOC – Associate File Type
ASSOC –关联文件类型

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

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
List Attributes
列表属性

更改为只读(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
Change To Given Child Directory
更改为给定的子目录

转到父目录(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.txtb.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
DATE – Display Current Date
DATE –显示当前日期

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命令删除文件。 我们将提供我们要删除的文件的名称。

LEARN MORE  What Is Command Line and Command Prompt In Windows Operating System?
了解更多信息Windows操作系统中的命令行和命令提示符是什么?

删除给定文件 (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
List All Files and Folders
列出所有文件和文件夹

列出隐藏的文件和文件夹(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
List Hidden Files and Folders
列出隐藏的文件和文件夹

列出特定的扩展文件(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
DRIVERQUERY – List Drivers and Properties
DRIVERQUERY –列出驱动程序和属性

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.txtb.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提供的可用命令。

LEARN MORE  How To Start Applications From Command Line In Windows Different Ways?
了解更多信息如何以Windows的不同方式从命令行启动应用程序?

列出所有命令 (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
List All Command
列出所有命令

帮助特定命令(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
Help For Specific Command
帮助特定命令

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
IPCONFIG – List Network Configuration Like IP Address
IPCONFIG –列出网络配置,如IP地址

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
LABEL – Add, Set or Remove Disk Labels
标签–添加,设置或删除磁盘标签

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?

如何在Windows命令行中使用Net Use命令?

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
PATH  – Display Path Variable
PATH –显示路径变量

暂停–停止当前正在运行的脚本(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
PING – Test Remote Hosts
PING –测试远程主机

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
SET – Display Environment Variables
SET –显示环境变量

关机–关闭系统(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
SYSTEMINFO – Display Computer and Operating System Information
SYSTEMINFO –显示计算机和操作系统信息

How To Open System Information Panel On Windows To Check Computer and Specification?

如何在Windows上打开系统信息面板以检查计算机和规格?

任务杀死–杀死任务和过程 (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
TASKLIST – List Current Tasks or Processes
任务列表–列出当前任务或过程

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
TIME – Display or Set Current Time
TIME –显示或设置当前时间

标题-设置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
TREE – Display Subdirectories As Tree
TREE –将子目录显示为树

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  VERcommand like below.

Windows操作系统和MSDOS具有不同的版本。 我们可以使用VER命令显示当前的操作系统和MSDOS版本,如下所示。

VER
VER - Display Windows or MSDOS Version
VER – Display Windows or MSDOS Version
VER –显示Windows或MSDOS版本

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.txt123.txt

XCOPY abc.txt 123.txt

Windows Copy Operation With Xcopy Command Tutorial With Examples

带有示例的Xcopy命令教程的Windows复制操作

LEARN MORE  What Is Command Line and Command Prompt In Windows Operating System?
了解更多信息Windows操作系统中的命令行和命令提示符是什么?

翻译自: https://www.poftut.com/batch-file-commands-for-windows-msdos/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值