All windows batch file commands

Batch Script — Commands

In this chapter, we will look at some of the frequently used batch commands.

S.No Commands & Description

This batch command shows the version of MS-DOS you are using.

This is a batch command that associates an extension with a file type (FTYPE), displays existing associations, or deletes an association.

This batch command helps in making changes to a different directory, or displays the current directory.

This batch command clears the screen.

This batch command is used for copying files from one location to the other.

This batch command deletes files and not directories.

This batch command lists the contents of a directory.

This batch command help to find the system date.

This batch command displays messages, or turns command echoing on or off.

This batch command exits the DOS console.

This batch command creates a new directory in the current location.

This batch command moves files or directories between directories.

This batch command displays or sets the path variable.

This batch command prompts the user and waits for a line of input to be entered.

This batch command can be used to change or reset the cmd.exe prompt.

This batch command removes directories, but the directories need to be empty before they can be removed.

Renames files and directories

This batch command is used for remarks in batch files, preventing the content of the remark from being executed.

This batch command starts a program in new window, or opens a document.

This batch command sets or displays the time.

This batch command prints the content of a file or files to the output.

This batch command displays the volume labels.

Displays or sets the attributes of the files in the curret directory

This batch command checks the disk for any problems.

This batch command provides a list of options to the user.

This batch command invokes another instance of command prompt.

This batch command compares 2 files based on the file size.

This batch command converts a volume from FAT16 or FAT32 file system to NTFS file system.

This batch command shows all installed device drivers and their properties.

This batch command extracts files from compressed .cab cabinet files.

This batch command searches for a string in files or input, outputting matching lines.

This batch command formats a disk to use Windows-supported file system such as FAT, FAT32 or NTFS, thereby overwriting the previous content of the disk.

This batch command shows the list of Windows-supplied commands.

This batch command displays Windows IP Configuration. Shows configuration by connection and the name of that connection.

This batch command adds, sets or removes a disk label.

This batch command displays the contents of a file or files, one screen at a time.

Provides various network services, depending on the command used.

This batch command sends ICMP/IP «echo» packets over the network to the designated address.

This batch command shuts down a computer, or logs off the current user.

This batch command takes the input from a source file and sorts its contents alphabetically, from A to Z or Z to A. It prints the output on the console.

This batch command assigns a drive letter to a local folder, displays current assignments, or removes an assignment.

This batch command shows configuration of a computer and its operating system.

This batch command ends one or more tasks.

This batch command lists tasks, including task name and process id (PID).

This batch command copies files and directories in a more advanced way.

This batch command displays a tree of all subdirectories of the current directory to any level of recursion or depth.

This batch command lists the actual differences between two files.

This batch command shows and configures the properties of disk partitions.

This batch command sets the title displayed in the console window.

Displays the list of environment variables on the current system.

Windows commands

All supported versions of Windows (server and client) have a set of Win32 console commands built in.

This set of documentation describes the Windows Commands you can use to automate tasks by using scripts or scripting tools.


The information that is contained in this topic applies to:

  • Windows Server 2019
  • Windows Server (Semi-Annual Channel)
  • Windows Server 2016
  • Windows Server 2012 R2
  • Windows Server 2012
  • Windows Server 2008 R2
  • Windows Server 2008
  • Windows 10
  • Windows 8.1

Command shell overview

The Command shell was the first shell built into Windows to automate routine tasks, like user account management or nightly backups, with batch (.bat) files. With Windows Script Host you could run more sophisticated scripts in the Command shell. For more information, see cscript or wscript. You can perform operations more efficiently by using scripts than you can by using the user interface. Scripts accept all Commands that are available at the command line.

Windows has two command shells: The Command shell and PowerShell. Each shell is a software program that provides direct communication between you and the operating system or application, providing an environment to automate IT operations.

PowerShell was designed to extend the capabilities of the Command shell to run PowerShell commands called cmdlets. Cmdlets are similar to Windows Commands but provide a more extensible scripting language. You can run Windows Commands and PowerShell cmdlets in Powershell, but the Command shell can only run Windows Commands and not PowerShell cmdlets.

For the most robust, up-to-date Windows automation, we recommend using PowerShell instead of Windows Commands or Windows Script Host for Windows automation.

You can also download and install PowerShell Core, the open source version of PowerShell.

Incorrectly editing the registry may severely damage your system. Before making the following changes to the registry, you should back up any valued data on the computer.

To enable or disable file and directory name completion in the Command shell on a computer or user logon session, run regedit.exe and set the following reg_DWOrd value:

To set the reg_DWOrd value, use the hexadecimal value of a control character for a particular function (for example, 0 9 is Tab and 0 08 is Backspace). User-specified settings take precedence over computer settings, and command-line options take precedence over registry settings.

Command-line reference A-Z

To find information about a specific command, in the following A-Z menu, click the letter that the command starts with, and then click the command name.

Batch file commands

In this tutorial, you will learn about batch file commands and how they are used in batch file scripting or programming.

As discussed in the previous tutorial, a batch file is an unformatted text file or script file which contains multiple batch file commands or instructions to achieve a certain task. It has extension of .bat or .cmd .

Batch file commands: Windows/DOS

For the ease of learning, we have listed all the batch file commands with relevant examples and explanations below. Please click on the commands to know the details.

List of batch file commands

Note: Batch file commands are not case sensitive


The batch command ASSOC associates a file extension with a file type, or list all associations.



As shown in above output, it displays the file association for .txt extension.

If only ASSOC is written and executed, it will display all the file associations for every extension, instead of just .txt extension.


The batch command ATTRIB is used to display the file attributes or set an attribute to a file in the working directory.


Now let us suppose we have a file note.txt in our working directory. We will display its file attributes and then make it hidden and read only by adding ‘ah’ and ‘r’ attributes to it. And finally, we will remove some attributes we added as well.


Here in this output, A means Archived, R means Read only and AH means Hidden file.


The batch command CD helps in navigating through different directories and changing directories or displaying current directory.




The batch command CHKDSK is used for checking error in the disk.



The batch command CHOICE provides a list of options to the user.



Now that script will produce following output.

Now the console waits for your input and once you enter your answer it will terminate.


The batch command CLS clears the screen.


This command just clears all the logs in command prompt screen.


The batch command CMD invokes a new command prompt window.



The batch command COMP compares the size of two files and checks if they are different in size.



The batch command CONVERTS the volumes or drives from one format to another i.e from FAT to NTFS.



The batch command COPY is used for copying files from one location to another.



The batch command DATE displays the current date in the system.



This command DATE displays system date in command prompt as shown above.


The batch command DEL is used for deleting files.


Note: DEL command only deletes files, not directories.


The batch command DIR lists all the contents of directories.



The batch command DISKPART shows the properties of a disk partition.


This script will ask for users permission to check the properties of disk partition and if allowed, will display following output in the console depending on disk properties.


The batch command DRIVERQUERY displays all the drivers installed and their properties.



This output shows the fraction of drivers list with their properties and installed date. DRIVERQUERY command shows all the drivers list, which is huge.


The batch command ECHO is used for echoing commands on/off and printing message to the console.



This command ECHO displays Hello in the console as shown above.

Besides printing message, echo is also used for deciding whether or not to display the command itself. Like in this example as well, in the first line we have turned OFF echo, which makes sure that commands themselves are not printed.

If that echo wasn’t turned off, then the output would have been like:


The batch command EXIT terminates and exits the console.


In this example, as soon as HI is printed in the console, EXIT command will terminate the program and close the output console.


The batch command EXPAND extracts the contents of .cab file.


This script will extract all the contents of xyz.cab file to the same location where xyz.cab is located.


The batch command FC finds the difference between the two files and displays them to console.


This script will find the difference in the content of both files and list out all of them.


The batch command FIND search the given file to find the desired string and if located, it displays the corresponding line in which the string exists.


This script will search for the string “find me” in example.txt file and if it exists in example.txt, it will display the corresponding line on the console.


The batch command FORMAT is used for formatting a drive of format FAT 16/32 or NTFS in Windows.


This script will format E drive and overwrite previous contents.


This might be the one of the most important batch file commands because with this HELP command we can know about all the other commands used in batch file or command prompt.


Now this will display all the available commands with their functionalities in the console.

Since the list of commands is so much more, we have sliced the list and shown few here.

Now that we have a list of batch file commands, we can also view details of their syntax and functionalities in following way:

Now this will display details of the copy command.

As you can see, it HELP COPY displays all the details about COPY command.


The batch command IPCONFIG displays Windows IP configuration.


This script will generate following output.

P.S: We have hidden iPV6 address in above output.


The batch command LABEL displays the label of a drive or volume and is also is used for adding, setting or removing a disk label.


Now this will display the label of your working directory and you can set, remove or add another label.

For example, my working directory is D: and has label ‘apps’. So, it will generate following output:


The batch command MD creates a new directory or folder in the working directory.


This program will create a new directory abc in current working location.


The batch command MORE displays the content of a file one by one.


This program will display the contents of example.txt line by line, one at a time.


This batch command moves files from one directory to another, rename the directories and move the directories as well.


In this way, MOVE command can be used to move files, directories and rename directories.


The batch command NET is used for many network functionalities depending upon the commands used.


To display the users:

This will generate following output:

Like users, there are many other commands:

  • 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


The batch command PATH displays the path variable or it can be used to set path variable.


This program will display the path of the current working directory.


The batch command PAUSE is used for holding the output screen till user enters a variable or a value.


This program will print hi in the console and show the message ‘Press any key to continue..’ and wait for the input from the user.


The batch command PING is used for sending ICMP/IP packets to the designated address over the network.



This script will send packets to address and output will be displayed as follows:


The batch command RD is used for removing the empty directories, directories with contents or files inside cannot be removed with RD command.



The batch command REM signifies comments in the batch script.


Anything written after REM is interpreted as a comment and is not executed in batch programs.


The batch command REN is used for renaming files and directories.



The batch command SET displays the list of environment variables of the system.



The batch command SHUTDOWN when invoked, shuts down the computer.



The batch command SORT is used to sort the content of the file alphabetically.


This script will sort the content of example.txt alphabetically either in ascending or descending order.


The batch command START is used to open a file or start a new program.


This program will start the application paint if it is in the working location, else you will have to explicitly indicate the path of that program as well.


The batch command SYSTEMINFO displays all the configuration of the computer and operating system.


This will generate following output depending upon the computer:

Of course, the details will be much more than this, but please try and look on your PC.


The batch command TASKKILL is used to terminate a running task


If you were to terminate the notepad running in your PC, then following script is used.


The batch command TASKLIST lists all the running tasks in the console.



The batch command TIME is used to display or set the system time.



The current time is displayed in the console.


The batch command TITLE sets new title for output console.


This script will set the title of output console to ‘New Console’. Thus the output console will look like:


The batch command TREE displays the tree diagram of the subdirectories to the last level.


I have a folder movies. SO, if I were to run TREE in that movie folder, it will create a tree of movies inside that folder and also the subdirectories where there is movie file and subtitle file.


This script will generate following output.


The batch command TYPE is used for displaying the content of a file to an output console.


This program will display all the contents of notes.txt to the console.


The batch command VER displays the version of Windows or MS-DOS.




The batch command VOL displays the current volume label of Windows.




The batch command XCOPY is similar to COPY command but COPY command copies single file whereas XCOPY command copies entire directories including subdirectories.


This script will copy test.txt from D drive to E drive.

So, these are the batch file commands along with examples.

We hope you find these batch file commands easy to learn. We will discuss more advanced concepts in next tutorials.

Читайте также:  Как восстановить загрузчика windows 10

Советы по настройке компьютера © 2021
Внимание! Информация, опубликованная на сайте, носит исключительно ознакомительный характер и не является рекомендацией к применению.