Batch Scripting Cheat Sheet



You can use the command reference to familiarize yourself with new and enhanced command-line tools, to learn about the command shell, and to automate command-line tasks by using batch files or scripting tools. Batch-Cheat-Sheet.md Batch Cheat Sheet. For more information on a specific command, type HELP command-name. Command Description; ASSOC. Batch Scripts are stored in simple text files containing lines with commands that get executed in sequence, one after the other. Scripting is a way by which one can alleviate this necessity by automating these command sequences in order to make one’s life at the shell easier and more productive.

To be functional, each DOS command must be entered in a particular way: this command entry structure is known as the command’s “syntax.” The syntax “notation” is a way to reproduce the command syntax in print.

Batch Cheat Sheet by ChaosJD (ChaosJD) via cheatography.com/99440/cs/21487/ File Redirects type file.txt sort give output of type to sort sort give content ( stdin) of file.txt echo ' hi' file.txt write ' hi' (stout) to file.txt type NUL file.txt create empty file rm file 2 errors.txt redi rects errors (st derr) ro errors.txt. Trace # takes your module or function and an example # data input, and traces the computational steps # that the data encounters as it progresses through the model @script # decorator used to indicate data-dependent # control flow within the code being traced.

For example, you can determine the items that are optional, by looking for information that is printed inside square brackets. The notation [d:], for example, indicates an optional drive designation. The command syntax, on the other hand, is how you enter the command to make it work.

To open the DOS command window in Windows simple press the “Windows Logo + r”, type cmd and then press Enter.

CommandSyntaxComments

APPEND

APPEND ;
APPEND [d:]path[;][d:]path[…]APPEND [/X:on|off][/path:on|off] [/E]
Displays or sets the search path for data files. DOS will search the specified path(s) if the file is not found in the current path.

ASSIGN

ASSIGN x=y […] /staRedirects disk drive requests to a different drive.

ATTRIB

ATTRIB [d:][path]filename [/S]ATTRIB [+R|-R] [+A|-A] [+S|-S] [+H|-H] [d:][path]filename [/S]Sets or displays the read-only, archive, system, and hidden attributes of a file or directory.

BACKUP

BACKUP d:[path][filename] d:[/S][/M][/A][/F:(size)] [/P][/D:date] [/T:time] [/L:[path]filename]Makes a backup copy of one or more files. (In DOS Version 6, this program is stored on the DOS supplemental disk.)

BREAK

BREAK =on|offUsed from the DOS prompt or in a batch file or in the CONFIG.SYS file to set (or display) whether or not DOS should check for a Ctrl + Break key combination.

BUFFERS

BUFFERS=(number),(read-ahead number)Used in the CONFIG.SYS file to set the number of disk buffers (number) that will be available for use during data input. Also used to set a value for the number of sectors to be read in advance (read-ahead) during data input operations.

CALL

CALL [d:][path]batchfilename [options]Calls another batch file and then returns to current batch file to continue.

CHCP

CHCP (codepage)Displays the current code page or changes the code page that DOS will use.

CHDIR

CHDIR (CD) [d:]path
CHDIR (CD)[..]
Displays working (current) directory and/or changes to a different directory.

CHKDSK

CHKDSK [d:][path][filename] [/F][/V]Checks a disk and provides a file and memory status report.

CHOICE

CHOICE [/C[:]keys] [/N][/S][/T[:]c,nn] Used to provide a prompt so that a user can make a choice while a batch program is running.

CLS (Clear Screen)

CLSClears (erases) the screen.

COMMAND

COMMAND [d:][path] [device] [/P][/E:(size)] [/MSG][/Y [/C (command)|/K (command)]Starts a new version of the DOS command processor (the program that loads the DOS Internal programs).

COMP

COMP [d:][path][filename] [d:][path][filename] [/A][/C][/D][/L][/N:(number)]Compares two groups of files to find information that does not match. (See FC command).

COPY

COPY [/Y|-Y] [/A][/B] [d:][path]filename [/A][/B] [d:][path][filename] [/V]or
COPY [/Y|-Y][/A][/B] [d:][path]filename+[d:][path]filename[…][d:][path][filename] [/V]
Copies and appends files.

COUNTRY

COUNTRY=country code,[,][d:][filename]Used in the CONFIG.SYS file to tell DOS to use country-specific text conventions during processing.

CTTY

CTTY (device)Changes the standard I/O (Input/Output) device to an auxiliary device.

DATE

DATE mm-dd-yyDisplays and/or sets the system date.

DBLSPACE

DBLSPACE / automount=drives
DBLSPACE /chkdsk [/F] [d:]DBLSPACE /compress d: [/newdrive=host:] [/reserve=size] [/F]DBLSPACE /create d: [/newdrive=host:] [/reserve=size] [/size=size]DBLSPACE /defragment [d:] ]/F]DBLSPACE /delete d:
DBLSPACE /doubleguard=0|1
DBLSPACE /format d:
DBLSPACE [/info] [d:]DBLSPACE /list
DBLSPACE /mount[=nnn] host: [/newdrive=d:]DBLSPACE /ratio[=ratio] [d:] [/all]DBLSPACE /size[=size] [/reserve=size] d:
DBLSPACE /uncompress d:
DBLSPACE /unmount [d:]
A program available with DOS 6.0 that allows you to compress information on a disk.

DEBUG

DEBUG [pathname] [parameters]An MS-DOS utility used to test and edit programs.

DEFRAG

DEFRAG [d:] [/F][/S[:]order] [/B][/skiphigh [/LCD|/BW|/GO] [/H]DEFRAG [d:] [/V][/B][/skiphigh] [/LCD]|/BW|/GO] [/H]Optimizes disk performance by reorganizing the files on the disk.

DEL (ERASE)

DEL (ERASE) [d:][path]filename [/P]Deletes (erases) files from disk.

DELOLDOS

DELOLDOS [/B]Deletes all files from previous versions of DOS after a 5.0 or 6.0 installation.

DELTREE

DELTREE [/Y] [d:]path [d:]path[...]Deletes (erases) a directory including all files and subdirectories that are in it.

DEVICE

DEVICE=(driver name)Used in the CONFIG.SYS file to tell DOS which device driver to load.

DEVICEHIGH

DEVICEHIGH=(driver name)Like DEVICE, DEVICEHIGH is used in the CONFIG.SYS file to tell DOS which device driver software to use for devices; however, this option is used to install the device driver into the upper memory area.

DIR

DIR [d:][path][filename] [/A:(attributes)] [/O:(order)] [/B][/C][/CH][/L][/S][/P][/W]Displays directory of files and directories stored on disk.

DISKCOMP

DISKCOMP [d:] [d:][/1][/8]Compares the contents of two diskettes.

DISKCOPY

DISKCOPY [d:] [d:][/1][/V][/M]Makes an exact copy of a diskette.

DOS

DOS=[high|low],[umb|noumb]Used in the CONFIG.SYS file to specify the memory location for DOS. It is used to load DOS into the upper memory area and to specify whether or not the upper memory blocks will be used.

DOSKEY

DOSKEY [reinstall] [/bufsize=size][/macros][/history][/insert|/overstrike] [macroname=]Loads the Doskey program into memory which can be used to recall DOS commands so that you can edit them.

DOSSHELL

DOSSHELL [/B] [/G:[resolution][n]]|[/T:[resolution][n]]Initiates the graphic shell program using the specified screen resolution.

DRIVPARM

DRIVPARM= /D:(number) [/C] [/F:(form factor)] [/H:(number)] [/I][ /N][/S:(number)] [/T:(tracks)]Used in the CONFIG.SYS file to set parameters for a disk drive.

ECHO

ECHO on|off
ECHO (message)
Displays messages or turns on or off the display of commands in a batch file.

EDIT

EDIT [d:][path]filename [/B][/G][/H][/NOHI]Starts the MS-DOS editor, a text editor used to create and edit ASCII text files.

EMM386

EMM386 [on|off|auto] [w=on|off]Enables or disables EMM386 expanded-memory support on a computer with an 80386 or higher processor.

EXE2BIN

EXE2BIN [d:][path]filename [d:][path]filenameConverts .EXE (executable) files to binary format.

EXIT

EXITExits a secondary command processor.

EXPAND

EXPAND [d:][path]filename [[d:][path]filename[ . . .]]Expands a compressed file.

FASTHELP

FASTHELP [command][command] /?Displays a list of DOS commands with a brief explanation of each.

FASTOPEN

FASTOPEN d:[=n][/X]Keeps track of the locations of files for fast access.

FC

FC [/A][/C][/L][/Lb n][/N][/T][/W][number] [d:][path]filename [d:][path]filename
or (for binary comparisons)
FC [/B][/number] [d:][path]filename [d:][path]filename
Displays the differences between two files or sets of files.

FCBS

FCBS=(number)Used in the CONFIG.SYS file to specify the number of file-control blocks for file sharing.

FDISK

FDISK [/status]Prepares a fixed disk to accept DOS files for storage.

FILES

FILES=(number)Used in the CONFIG.Sys file to specify the maximum number of files that can be open at the same time.

FIND

FIND [/V][/C][/I][/N] ÒstringÓ [d:][path]filename[...]Finds and reports the location of a specific string of text characters in one or more files.

FOR

FOR %%(variable) IN (set) DO (command)
or (for interactive processing)
FOR %(variable) IN (set) DO (command)
Performs repeated execution of commands (for both batch processing and interactive processing).

FORMAT

FORMAT d:[/1][/4][/8][/F:(size)] [/N:(sectors)] [/T:(tracks)][/B|/S][/C][/V:(label)] [/Q][/U][/V]Formats a disk to accept DOS files.

GOTO

GOTO (label)Causes unconditional branch to the specified label.

GRAFTABL

GRAFTABL [(code page)]GRAFTABL [status]Loads a table of character data into memory (for use with a color/graphics adapter).

GRAPHICS

GRAPHICS [printer type][profile] [/B][/R][/LCD][/PB:(id)] [/C][/F][/P(port)]Provides a way to print contents of a graphics screen display.

HELP

HELP [command] [/B][/G][/H][/NOHI]Displays information about a DOS command.

IF

IF [NOT] EXIST filename (command) [parameters]IF [NOT] (string1)(string2) (command) [parameters]IF [NOT] ERRORLEVEL (number) (command) [parameters]Allows for conditional operations in batch processing.

INCLUDE

INCLUDE= blocknameUsed in the CONFIG.SYS file to allow you to use the commands from one CONFIG.SYS block within another.

INSTALL

INSTALL=[d: ][path]filename [parameters]Used in the CONFIG.SYS file to load memory-resident programs into conventional memory.

INTERLINK

INTERLINK [client[:]=[server][:]]Connects two computers via parallel or serial ports so that the computers can share disks and printer ports.

INTERSVR

INTERSVR [d:][...][/X=d:][...] [/LPT:[n|address]] [/COM:[n|address]][/baud:rate] [/B][/V]INTERSVR /RCOPYStarts the Interlink server.

JOIN

JOIN d: [d:path]JOIN d: [/D]Allows access to the directory structure and files of a drive through a directory on a different drive.

KEYB

KEYB [xx][,][yyy][,][d:][path]filename [/E][/ID:(number)]Loads a program that replaces the support program for U. S. keyboards.

LABEL

LABEL [d:][volume label]Creates or changes or deletes a volume label for a disk.

LASTDRIVE

LASTDRIVE=(drive letter)Used in the CONFIG.SYS file to set the maximum number of drives that can be accessed.

LOADFIX

LOADFIX [d:][path]filename [parameters]Ensures that a program is loaded above the first 64K of conventional memory, and runs the program.

LOADHIGH

LOADHIGH (LH) [d:][path]filename [parameters]Loads memory resident application into reserved area of memory (between 640K-1M).

MEM

MEM [/program|/debug|/classify|/free|/module(name)] [/page]Displays amount of installed and available memory, including extended, expanded, and upper memory.

MEMMAKER

MEMMAKER [/B][/batch][/session][/swap:d] [/T][/undo][/W:size1,size2]Starts the MemMaker program, a program that lets you optimize your computer's memory.

MENUCOLOR

MENUCOLOR=textcolor,[background]Used in the CONFIG.SYS file to set the colors that will be used by DOS to display text on the screen.

MENUDEFAULT

MENUDEFAULT=blockname, [timeout]Used in the CONFIG.SYS file to set the startup configuration that will be used by DOS if no key is pressed within the specified timeout period.

MENUITEM

MENUITEM=blockname, [menutext]Used in the CONFIG.SYS file to create a start-up menu from which you can select a group of CONFIG.SYS commands to be processed upon reboot.

MIRROR

MIRROR [d:]path [d:] path [...]MIRROR [d1:][d2:][...] [/T(drive)(files)] [/partn][/U][/1]Saves disk storage information that can be used to recover accidentally erased files.

MKDIR

MKDIR (MD) [d:]pathCreates a new subdirectory.

MODE

MODE n
MODE LPT#[:][n][,][m][,][P][retry]MODE [n],m[,T]MODE (displaytype,linetotal)
MODE COMn[:]baud[,][parity][,][databits][,][stopbits][,][retry]MODE LPT#[:]=COMn [retry]MODE CON[RATE=(number)][DELAY=(number)]MODE (device) CODEPAGE PREPARE=(codepage) [d:][path]filename
MODE (device) CODEPAGE PREPARE=(codepage list) [d:][path]filename
MODE (device) CODEPAGE SELECT=(codepage)
MODE (device) CODEPAGE [/STATUS]MODE (device) CODEPAGE REFRESH
Sets mode of operation for devices or communications.

MORE

MORE < (filename or command)
(name)|MORE
Sends output to console, one screen at a time.

MOVE

MOVE [/Y|/-Y] [d:][path]filename[,[d:][path]filename[...]] destinationMoves one or more files to the location you specify. Can also be used to rename directories.

MSAV

MSAV [d:] [/S|/C][/R][/A][/L][/N][/P][/F][/video][/mouse]MSAV /videoScans your computer for known viruses.

MSBACKUP

MSBACKUP [setupfile] [/BW|/LCD|/MDA]Used to backup or restore one or more files from one disk to another.

MSCDEX

MSCDEX /D:driver [/D:driver2. . .] [/E][/K][/S][/V][/L:letter] [/M:number]Used to gain access to CD-ROM drives (new with DOS Version 6).

MSD

MSD [/B][/I]MSD [/I] [/F[d:][path]filename [/P[d:][path]filename [/S[d:][path]filenameProvides detailed technical information about your computer.

NLSFUNC

NLSFUNC [d:][path]filenameUsed to load a file with country-specific information.

NUMLOCK

NUMLOCK=on|offUsed in the CONFIG.SYS file to specify the state of the NumLock key.

PATH

PATH;
PATH [d:]path[;][d:]path[...]
Sets or displays directories that will be searched for programs not in the current directory.

PAUSE

PAUSE [comment]Suspends execution of a batch file until a key is pressed.

POWER

POWER [adv:max|reg|min]|std|off]Used to turn power management on and off, report the status of power management, and set levels of power conservation.

PRINT

PRINT [/B:(buffersize)] [/D:(device)] [/M:(maxtick)] [/Q:(value] [/S:(timeslice)][/U:(busytick)] [/C][/P][/T] [d:][path][filename] [...]Queues and prints data files.

PROMPT

PROMPT [prompt text] [options]Changes the DOS command prompt.

RECOVER

RECOVER [d:][path]filename
RECOVER d:
Resolves sector problems on a file or a disk. (Beginning with DOS Version 6, RECOVER is no longer available ).

REM

REM [comment]Used in batch files and in the CONFIG.SYS file to insert remarks (that will not be acted on).

RENAME (REN)

RENAME (REN) [d:][path]filename [d:][path]filenameChanges the filename under which a file is stored.

REPLACE

REPLACE [d:][path]filename [d:][path] [/A][/P][/R][/S][/U][/W]Replaces stored files with files of the same name from a different storage location.

RESTORE

RESTORE d: [d:][path]filename [/P][/S][/B:mm-dd-yy] [/A:mm-dd-yy][/E:hh:mm:ss] [/L:hh:mm:ss] [/M][/N][/D]Restores to standard disk storage format files previously stored using the BACKUP command.

RMDIR (RD)

RMDIR (RD) [d:]pathRemoves a subdirectory.

SCANDISK

SCANDISK [d: [d: . . .]|/all][/checkonly|/autofix[/nosave]|/custom][/surface][/mono][/nosummay]SCANDISK volume-name[/checkonly|/autofix[/nosave]|/custom][/mono][/nosummary]SCANDISK /fragment [d:][path]filename
SCANDISK /undo [undo-d:][/mono]
Starts the Microsoft ScanDisk program which is a disk analysis and repair tool used to check a drive for errors and correct any problems that it finds.

SELECT

SELECT [d:] [d:][path] [country code][keyboard code]Formats a disk and installs country-specific information and keyboard codes (starting with DOS Version 6, this command is no longer available).

SET

SET (string1)=(string2)Inserts strings into the command environment. The set values can be used later by programs.

SETVER

SETVER [d:]:path][filename (number)][/delete][/quiet]Displays the version table and sets the version of DOS that is reported to programs.

SHARE

SHARE [/F:space] [/L:locks]Installs support for file sharing and file locking.

SHELL

SHELL=[d:][path]filename [parameters]Used in the CONFIG.SYS file to specify the command interpreter that DOS should use.

SHIFT

SHIFTIncreases number of replaceable parameters to more than the standard ten for use in batch files.

SORT

SORT [/R][/+n] < (filename)
SORT [/R][/+n] > (filename2)
Sorts input and sends it to the screen or to a file.

STACKS

STACKS=(number),(size)Used in the CONFIG.SYS file to set the number of stack frames and the size of each stack frame.

SUBMENU

SUBMENU=blockname, [menutext]Used in the CONFIG.SYS file to create a multilevel menu from which you can select start-up options.

SUBST

SUBST d: d:path
SUBST d: /D
Substitutes a virtual drive letter for a path designation.

SWITCHES

SWITCHES= [/K][/F][/N][/W]Used in the CONFIG.SYS file to configure DOS in a special way; for example, to tell DOS to emulate different hardware configurations.

SYS

SYS d:Transfers the operating system files to another disk.

TIME

TIME hh:mm[:ss][.cc][A|P]Displays current time setting of system clock and provides a way for you to reset the time.

TREE

TREE [d:][path] [/A][/F]Displays directory paths and (optionally) files in each subdirectory.

TYPE

TYPE [d:][path]filenameDisplays the contents of a file.

UNDELETE

UNDELETE [d:][path][filename] [/DT|/DS|/DOS]UNDELETE [/list|/all|/purge[d:]|/status|/load|/U|/S[d:]|/Td:[-entries]]Restores files deleted with the DELETE command.

UNFORMAT

UNFORMAT d: [/J][/L][/test][/partn][/P][/U]Used to undo the effects of formatting a disk.

VER

VERDisplays the DOS version number.

VERIFY

VERIFY on|offTurns on the verify mode; the program checks all copying operations to assure that files are copied correctly.

VOL

VOL [d:]Displays a disk's volume label.

VSAFE

VSAFE [/option[+|-]...] [/NE][/NX][Ax|/Cx] [/N][/D][/U]VSAFE is a memory-resident program that continuously monitors your computer for viruses and displays a warning when it finds one.

XCOPY

XCOPY [d:][path]filename [d:][path][filename] [/A][/D:(date)] [/E][/M][/P][/S][/V][/W][Y-Y]Copies directories, subdirectories, and files.


Help

help comman­dNamecomman­dName /?help --> show all system commands

All System Commands

help

Clear Screen

Clear Screencls

Shortcuts

TabAutoco­mpletearrow keys up/downback/f­orward history commandsControl + Cstops current commandALT + F7clears the historyF7shows the history

Directory Make & Remove

mkdir
subdir­ectorycreates new subdir­ectorymkdir subdir­/su­bsubdircreates subdir & subdir­/su­bsubdir
Hint: creates it, if they aren't existingrmdirremoves an empty dirrmdir /s directoryremoves directory with contentrmdir /s /q directoryremoves directory with content & skips y/n question

Directory copy

copy src dstcopy filescopy /Y src destcopy files overwrites with­out quesitonxcopy /s src destcopies dirs and subdirs except empty onesxcopy /YS src destas above with­out ask to overwritexcopy /YS src serv­er­sharecopy to network sharerobocopy /S src destBatch Scripting Cheat Sheetcopies dirs and subdirs except empty onesrobocopy /YS src destas above without ask to overwrite

Parameters

%0Name of Script%1 ... %9Parameter 1 ... Parameter 9%*prints all parameters as a string(one line)
for %%x in (%*) do echo %%xaccess it through a for loop works with > 10 parameters

Pass Parameters to sub script

parame­ter­s_s­cri­pt.bat@echo off
call parame­ter­s_s­ubs­cri­pt.bat %*
EXIT /B %error­level%parame­ter­s_s­ubs­cri­pt.bat@ECHO off
echo subscript called with %*
EXIT /B 0EXIT /B specifies to exit the current batch scropt instead of cmd.exe. If executed from outside a batch script, it will quit cmd.exe

Arrays Way2

set array[0]=0
set array[1]=1
...set value to a specific array elementecho %array[0]%
echo %array[1]%access to array elementsmissing loop over elements: indexed

Functions: label and goto

echo 'Hi:'
goto :good:bad
echo 'I don't like scripting'
goto :eof:good
echo 'I like scripting'
goto :eof

Double­Cli­ckE­xec­ution

Windows Batch Scripting Tutorial

@ECHO off
setlocal
REM check for intera­ctive sesseion
SET intera­ctive=0
ECHO %CMDCM­DLINE% | FINDSTR /L %COMSPEC% >NUL 2>&1
IF %ERROR­LEVEL% EQ SET intera­ctive=1
ECHO do work
REM pause if intera­ctive (doubl­e-c­licked execution)
IF '­%in­era­cti­ve%­' '­0' PAUSE
EXIT /B 0FINDSTR /L is use search string literally

Navigation

realativeparent directorycd .., cd..subdir­ectorycd subdir­ectoyabsolutecd C:Windowscd Windowschange driveZ:

Wildcards

? (file?.txt)one arbitary character* ( *.bat)arbitary characters (0,1 or more)

File Show

type fileshow file contentmoreshow file content page­wisesort fileshow file content sorted

Directory show Content

current folderdirabsolute pathdir C:Windowsdir Y:different drivedir /Bonly show file names and directory names

Batch Files User Input

@ echo off
set /P name='Input yor name: 'Syntax: set /P var=pr­ompt:echo Hi %name%variable call

Batch Files File Input

@echo off
echo Bill > file
echo Gate >> fileset /P fileco­ntent =< file
echo First Line: %filec­ontent%set /P var=< fileFOR /f %%f in (file) Do (
echo %%f
)REM print each line in file

Variables

setlocal
set MY_ENV=abc
endlocalOnly active in the current batch file (local)set MY_ENV=abccreates or changes an enviro­nment variable that is active in the cmd. (global)setshows the active enviro­nment variablesecho %USERNAME%print variable outdefined MY_VARreturns
Batch scripting cheat sheet printable0 => Execution was successful

Batch Scripting 101

>0 => Execution failed

IF Control Structures

IF test (command) ELSE (command)Syntax

Control structures For

for {%%|%}­<Va­ria­ble> in (<S­et>) do <Co­mma­nd> [<C­omm­and­Lin­eOp­tio­ns>]cmd.exe use ->%batch script use ->­%%

Functions

call :print­_name Florianecho print_name exitst with %error­level%goto :eof:printname
echo Hit %1
exit /B 0 <- REM sets exit status of :print­_name

File Rename & Move

rename file1 file2renamef filte1 to file2move file1 dirmove file 1 to dir (path dir/file1)move file1 dir/file2moves and renames file1 to file2 (path: dir/file2) file2 is overwr­itten from file1move /Y file1 file2moves and overwrites file1 to file2 with­out asking

File Names

Case-I­nse­nsitiveMax. 260 characters incl. invisible termin­ating null characterspaces and character set 128 - 255 allowedNever <, >, :, ', /, , |, ?, *Hint: A-Z, a-z, 0-9, _, spaces, ( underscore as space )*.bat & *.cmddir /B --> only show file names and directory Names

Directory Rename & Move

rename dir1 dir2renames dir1 in dir2move dir1 dir2if dir2 exist: dir1 into dir2 (path: dir2/d­ir1), else rename dir1 to dir2move file1 dir/file2file 2 is deleted. file1 get the name of file2 ans is set at the position of file2 with asking (Yes/N­o/All)move /Y file1 file2file 2 is deleted. file1 get the name of file2 ans is set at the position of file2 with­out asking.

File Redirects

type file.txt | sort

Batch Scripting Cheat Sheet Example

give output of type to sortsort < file.txtgive content ( stdin) of file.txtecho '­hi' > file.txtwrite '­hi' (stout) to file.txttype NUL > file.txtcreate empty filerm file 2> errors.txtredi­rectsBatch Scripting Cheat Sheet errors­(st­derr) ro errors.txtrm file 2> NULdiscard errorsrm file 2>&1redi­rect stderr to stdoutecho '­you­' >> file.txtappend '­you­' to file.txt

Comment

REMPräfix after them the text

Calcul­ation

set /a i=0
echo i=%i%set /a i=1+1 Operatoren +, -, *, /set /a i+=1 Operatoren +, -, *, /

Arrays Way1

set arra­y=1 2 3 4
%array%(echo) all Array elementsfor %%a in (%array%) do (
echo%%a
)loop over elementsset array=­(and nothing else)unset vari­able or array

Control Struct­ures: Comparison Operators

OperatorInfoEqualEQUEqualNEQ!=Not equalLSS<LessLEQ<=Less than or equal toGTR>Greater thanGEQ

Batch Commands Cheat Sheet

>=Greater than or equalNOT!Not

Editors

NotepadNotepad++Visual­Stu­dioCode

Editors

NotepadNotepad++Visual­Stu­dioCodeAtom

Terminals

cmd.exeWindows TerminalConEmucmder

Batch Filex Exit / Return

Specify exit code:echo 'abc'
exit 0Query error levelecho %ERROR­LEVEL%Exit/R­eturn codes0 => Execution was successful
>0 => Execution fiales with code X