Thursday, May 8, 2025

MS-DOS Command

1. ECHO

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

Syntax

ECHO “string”

Example

The following example shows the different variants of the dir command.

 

Rem Turns the echo on so that each command will be shown as executed

echo on

echo "Hello World"

Rem Turns the echo off so that each command will not be shown when executed

@echo off

echo "Hello World"

Rem Displays the contents of the PATH variable

echo %PATH%

Output

The following output will be displayed in the command prompt.

 

C:\>Rem Turns the echo on so that each command will be shown as executed

C:\>echo on

C:\>echo "Hello World"

"Hello World"

C:\>Rem Turns the echo off so that each command will not be shown when executed

"Hello World"

C:\Users\ADMINI~1\AppData\Local\Temp

 

2. DATE

This command gets the system date.

Syntax

DATE

Example

@echo off

echo %DATE%

Output

The current date will be displayed in the command prompt. For example,

Mon 12/28/2015

 

3. TIME

This command sets or displays the time.

Syntax

TIME

Example

@echo off

echo %TIME%

Output

The current system time will be displayed. For example,

22:06:52.87

 

4. START

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

Syntax

START “programname”

Example

@echo off

start notepad.exe

Output

When the batch file is executed, a new notepad windows will start.

 

5. VOL

This batch command displays the volume labels.

Syntax

VOL

Example

@echo off

VOL

Output

The output will display the current volume label. For example,

Volume in drive C is Windows8_OS

Volume Serial Number is E41C-6F43

 

6. Chkdsk

This batch command checks the disk for any problems.

Syntax

Chkdsk

Example

@echo off

Chkdsk

Output

The above command starts checking the current disk for any errors.

 

7. COPY

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

Syntax

Copy [source] [destination]

The files will be copied from source to destination location.

Example

The following example shows the different variants of the copy command.

@echo off

cd

Rem Copies lists.txt to the present working directory.

If there is no destination identified , it defaults to the present working directory.

copy c:\lists.txt

Rem The file lists.txt will be copied from C:\ to C:\tp location

copy C:\lists.txt c:\tp

Rem Quotation marks are required if the file name contains spaces

copy “C:\My File.txt”

Rem Copies all the files in F drive which have the txt file extension to the

current working directory copy

F:\*.txt

Rem Copies all files from dirA to dirB. Note that directories nested in dirA will not be copied

copy C:\dirA dirB

 

Output

All actions are performed as per the remarks in the batch file.

 

8. DEL

This batch command deletes files and not directories.

Syntax

del [filename]

Example

The following example shows the different variants of the del command.

@echo off

Rem Deletes the file lists.txt in C:\

del C:\lists.txt

Rem Deletes all files recursively in all nested directories

del /s *.txt

Rem Deletes all files recursively in all nested directories , but asks for the

confirmation from the user first

Del /p /s *.txt


Output

All actions are performed as per the remarks in the batch file.

 

9. VER

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

Syntax

Ver

Example

@echo off

Ver


Output

The output of the above command is as follows. The version number will depend upon the operating system you are working on.

Microsoft Windows [Version 6.3.9600]

 

 10. DIR

This batch command lists the contents of a directory.

Syntax

dir

Example

The following example shows the different variants of the dir command.

@echo off

Rem All the directory listings from C:\ will be routed to the file lists.txt

dir C:\>C:\lists.txt

Rem Lists all directories and subdirectories recursively

dir /s

Rem Lists the contents of the directory and all subdirectories recursively, one

file per line, displaying complete path for each listed file or directory.

dir /s /b

Rem Lists all files with .txt extension.

dir *.txt

Rem Includes hidden files and system files in the listing.

dir /a

Rem Lists hidden files only.

dir /ah

 

Output

All actions are performed as per the remarks in the batch file.

 

11. MD

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

Syntax

md [new directory name]

Example

@echo off

md newdir

cd newdir

cd Rem “Goes back to the parent directory and create 2 directories”

cd..

md newdir1 newdir1

cd newdir1

cd

cd..

cd newdir2

cd

 

Output

The above command produces the following output.

C:\newdir

C:\newdir1

C:\newdir2

 

12. RD

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

Syntax

rd [directoryname]

Example

The following example shows the different variants of the rd command.

@echo off

Rem removes the directory called newdir

rd C:\newdir

Rem removes 2 directories

rd Dir1 Dir2

Rem Removes directory with spaces

rd "Application A"

Rem Removes the directory Dir1 including all the files and subdirectories in it rd /s Dir1

Rem Removes the directory Dir1 including all the files and subdirectories in it but

asks for a user confirmation first.

rd /q /s Dir1

 

Output

All actions are performed as per the remarks in the batch file.

 

13. REN

Renames files and directories

Syntax

ren [oldfile/dirname] [newfile/dirname]

Renames the file name from the old file/dir name to the new one.

Example

@echo off

ren C:\lists.txt C:\newlists.txt

 

Output

The file lists.txt will be renamed to newlists.txt.

 

14. REM

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

Syntax

REM remark description

Example

@echo off

REM This is a batch file

 

Output

None

 

15. FORMAT

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.

Syntax

format [drive]

Where drive is the drive which needs to be formatted.

Example

@echo off

format D:\

 

Output

With the above command, D drive will be formatted.

 

16. SHUTDOWN

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

 Syntax

shutdown

 Example

@echo off

shutdown

 

Output

If the user executing the batch files has the relevant rights, the computer will be shutdown.

 

17. SYSTEMINFO

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

 Syntax

Systeminfo

 Example

@echo off

Systeminfo

 

Output

The above command will show the system information on the current system. Following is a subset of the output.

 

Host Name:                WIN-50GP30FGO75

OS Name:                  Microsoft Windows Server 2012 R2 Standard

OS Version:               6.3.9600 N/A Build 9600

OS Manufacturer:    Microsoft Corporation

OS Configuration:     Standalone Server

OS Build Type:           Multiprocessor Free

Registered Owner:    Windows User

Registered Organization: 

Product ID:               00252-70000-00000-AA535

Original Install Date:    12/13/2015, 12:10:16 AM

System Boot Time:         12/28/2015, 4:43:04 PM

System Manufacturer:      LENOVO

System Model:                    20287

System Type:                        x64-based PC

 

18. TREE

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

 Syntax

Tree

  Example

@echo off

Tree

 

Output

The above command will display the tree structure of the current directory. Following is an example of the output.

 

Folder PATH listing for volume Windows8_OS

Volume serial number is E41C-6F43

C:.

├───newdir

├───newdir1

└───newdir2

  

19. TITLE

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

 Syntax

TITLE [Tilename]

Where tilename is the new name to be given to the title of the command prompt window.

 Example

@echo off

Title “New Windows Title”

 

Output

The above command will change the title of the window to “New Windows Title”.

 

20. PING

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

 Syntax

PING [address]

Where address is the IP address or hostname of the destination system.

 Example

@echo off

Ping 127.0.0.1

 

Output

The above command will send ICMP/IP "echo" packets to the destination address 192.168.0.1. Following is an example of the output.

 

Pinging 127.0.0.1 with 32 bytes of data:

Reply from 127.0.0.1: bytes = 32 time<1ms TTL = 128

Reply from 127.0.0.1: bytes = 32 time<1ms TTL = 128

Reply from 127.0.0.1: bytes = 32 time<1ms TTL = 128

Reply from 127.0.0.1: bytes = 32 time<1ms TTL = 128

 

Ping statistics for 127.0.0.1:

   Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

   Minimum = 0ms, Maximum = 0ms, Average = 0ms