Batch file commands

Batch commands

In my previous article, we have seen the introduction of the batch file (batch script). In this article, I will describe some important commands of the batch file which frequently used. Below find the list of the commands.

Note: Batch file commands are not case sensitive.

ECHO

ECHO command is used to display the message on the console or turns echoing commands on/off.

Example,

 

Batch file commands

You can see that in below example command itself displaying on the console. So using the echo you can also off the displaying the commands on the console.

See example,

 

Batch file commands

CLS

This command is used to clear the console screen.

Example,

 

DEL

DEL command is used to delete files.

Syntax,

del [filename]

Example,

  • To delete a single file Test.txt.

  • Delete all the files of .txt extensions and ask for confirmation before deleting.

  • Delete all the files of .txt extensions and not ask for confirmation before deleting.

 

DIR

DIR command lists all the contents of directories.

  • List all the contents of the current directory.

  • Lists all files with .txt extension.

  • Lists all hidden files only.

  • List files with hidden files.

 

EXIT

EXIT command terminates and exits the console.

Example,

 

COPY

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

Syntax,

Copy [source] [destination]

Example,

In below, I am copying a file (Test.txt) from one drive (D) to another drive (E).

 

DATE

DATE command displays the current date of the system.

Example,

 

date batch comm

 

MOVE

MOVE command moves files or directories between directories or renames the directories.

Syntax,

MOVE [source] [destination]

Example,

  • move Test.txt from dir1 to dir2.

  • Rename directory dir1 to dir2.

  • Rename fileTest.txt to Test1.txt.

  • Move directory dir1 from E:\ to E:\Test.

 

PAUSE

PAUSE command is used for holding the console screen till user enters input value.

 

Leave a Reply