Batch File Commands For Windows MSDOS

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/batch-file-commands-for-windows-msdos/
PINTEREST
PINTEREST
INSTAGRAM

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

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

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.

List Attributes
List Attributes

Change To Read Only

We can change the file attribute to read only which will made given file uneditable.

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.

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.

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.

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.

Change Drive or Partition

We can also change the current partition. We will change to the drive :d in this example.

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.

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.

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.

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.

LEARN MORE  What Version Of Windows Do I Have?

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

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

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.

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

Delete Given File

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

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.

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

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.

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

DISKPART – Show and Change Disk Partition and Properties

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

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

Print Environment Variable

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

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.

LEARN MORE  Introduction To Bash Scripting

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.

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.

FORMAT – Change File System

Another command to change File System is FORMAT command. We will also provide the partition we want to format.

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.

List All Command

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

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

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.

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.

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.

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.

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

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.

LEARN MORE  Nmap Script and Version Scan

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

SET – Display Environment Variables

We can list current environment variables with the SET command.

SET - Display Environment Variables
SET – Display Environment Variables

SHUTDOWN – Shutdown the System

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

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

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

SYSTEMINFO – Display Computer and Operating System Information

We can use SYSTEMINFO in order to list and display computer, operating system and software information.

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

TASKLIST – List Current Tasks or Processes

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

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.

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

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

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

Windows Copy Operation With Xcopy Command Tutorial With Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/batch-file-commands-for-windows-msdos/
PINTEREST
PINTEREST
INSTAGRAM