Batch File Commands For Windows MSDOS – POFTUT

Batch File Commands For 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.

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

$ cmd.exe mybatchfile.txt

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 ".exe"
ASSOC - Associate File Type
ASSOC – Associate File Type

As we can see from output that .exe extension is associated with executable file .

If we do not provide a parameter ASSOC will list all existing associations with related extensions.

ASSOC

ATTRIB- List File Attributes

ATTRIB command is used to list, display and change file attributes about files, folders and directories.

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.

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.

attrib -r msdia80.dll

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.

Change To Given Child Directory

We will start by changing given child directory. We will first use DIR to list directories.

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.

cd d:

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

Windows Chkdsk Utility Tutorial with Examples To Fix File System Errors

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.

ECHO You want tea?

CHOISE /c YN /m "Yes or No"

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

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

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

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: .

CONVERT D:\

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 c:\a.txt d:\

DATE – Display Current Date

We can use %DATE% variable which holds the current date. We will print to the console with the echo command.

echo %DATE%
DATE - Display Current Date
DATE – Display Current Date

DEL – Delete Files

We can delete files with the DEL command. We will provide the name of the file we want to delete.

LEARN MORE  Shell Scripting Languages Examples, Bash, Sh, Python, Powershell, MSDOS, PHP, Tcl, Perl

Delete Given File

We will delete file named 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.

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.

DEL /p *.txt

DIR – List File and Folders

We can list current working and given directory files and folders with the DIR command like below.

List All Files and Folders

We can use DIR without any option to list all files and folders for the current working directory

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.

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"

DISKPART – Show and Change Disk Partition and Properties

We can use DISKPART command in order to list, display and change disk partition properties.

DISKPART

Windows Diskpart Command Tutorial with Examples To Format Disk

DRIVERQUERY – List Drivers and Properties

We can use DRIVERQUERY in order to list installed device drivers and related properties with dates.

DRIVERQUERY
DRIVERQUERY - List Drivers and Properties
DRIVERQUERY – List Drivers and Properties

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.

Print Given String

We will print given string which is "Hello World" in this case.

ECHO "Hello World"

Print Environment Variable

We can print given environment variable like %DATE% in this case

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

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

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 "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 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.

LEARN MORE  How To Start Applications From Command Line In Windows Different Ways?

List All Command

Without any option we can list all commands provided by MSDOS with HELP command like below.

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 dir
Help For Specific Command
Help For Specific Command

IPCONFIG – List Network Configuration Like IP Address

IPCONFIG will list information about the current system network interfaces and IP configuration.

IPCONFIG
IPCONFIG - List Network Configuration Like IP Address
IPCONFIG – List Network Configuration Like IP Address

Windows Ipconfig Command Tutorial With Examples To List, Change, Renew IP Configuration

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 D:\
LABEL - Add, Set or Remove Disk Labels
LABEL – Add, Set or Remove Disk Labels

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

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 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 c:\abc.txt d:\xyz.txt

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.

  • 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  – Display Path Variable

PATH variable provides commands and applications to run. We can list these paths with the PATH variable.

echo %PATH%
PATH  - Display Path Variable
PATH  – Display Path Variable

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

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 google.com
PING - Test Remote Hosts
PING – Test Remote Hosts

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

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 This is a comment no command :)

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

SET – Display Environment Variables

We can list current environment variables with the SET command.

SET
SET - Display Environment Variables
SET – Display Environment Variables

SHUTDOWN – Shutdown the System

We can shutdown the system with the SHUTDOWN command like below.

SHUTDOWN

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

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 notepad.exe

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 - Display Computer and Operating System Information
SYSTEMINFO – Display Computer and Operating System Information

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 /im notepad.exe

TASKLIST – List Current Tasks or Processes

We can list currently running tasks and processes with the TASKLIST command.

TASKLIST
TASKLIST - List Current Tasks or Processes
TASKLIST – List Current Tasks or Processes

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.

echo %TIME%
TIME - Display or Set Current Time
TIME – Display or Set Current Time

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 MYCONSOLE

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 - Display Subdirectories As Tree
TREE – Display Subdirectories As Tree

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.

VER
VER - Display Windows or MSDOS Version
VER – Display Windows or MSDOS Version

VOL  – Display Volume Label

We can displat current volume label with the VOL command.

VOL

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

Windows Copy Operation With Xcopy Command Tutorial With Examples

LEARN MORE  How To Start Applications From Command Line In Windows Different Ways?

Leave a Comment