CommandLine_BatchScript
CommandLine_BatchScript
1
For more information on a specific command, type HELP command-name
2
MD --- Creates a directory.
MKDIR --- Creates a directory.
MKLINK --- Creates Symbolic Links and Hard Links
MODE --- Configures a system device.
MORE --- Displays output one screen at a time.
MOVE --- Moves one or more files from one directory to another directory.
OPENFILES --- Displays files opened by remote users for a file share.
PATH --- Displays or sets a search path for executable files.
PAUSE --- Suspends processing of a batch file and displays a message.
POPD --- Restores the previous value of the current directory saved by PUSHD.
PRINT --- Prints a text file.
PROMPT --- Changes the Windows command prompt.
PUSHD --- Saves the current directory then changes it.
RD --- Removes a directory.
RECOVER --- Recovers readable information from a bad or defective disk.
REM --- Records comments (remarks) in batch files or CONFIG.SYS.
REN --- Renames a file or files.
RENAME --- Renames a file or files.
REPLACE --- Replaces files.
RMDIR --- Removes a directory.
ROBOCOPY --- Advanced utility to copy files and directory trees
SET --- Displays, sets, or removes Windows environment variables.
SETLOCAL --- Begins localization of environment changes in a batch file.
SC --- Displays or configures services (background processes).
SCHTASKS --- Schedules commands and programs to run on a computer.
SHIFT --- Shifts the position of replaceable parameters in batch files.
SHUTDOWN --- Allows proper local or remote shutdown of machine.
SORT --- Sorts input.
START --- Starts a separate window to run a specified program or command.
SUBST --- Associates a path with a drive letter.
SYSTEMINFO --- Displays machine specific properties and configuration.
TASKLIST --- Displays all currently running tasks including services.
TASKKILL --- Kill or stop a running process or application.
TIME --- Displays or sets the system time.
TITLE --- Sets the window title for a CMD.EXE session.
TREE --- Graphically displays the directory structure of a drive or path.
TYPE --- Displays the contents of a text file.
VER --- Displays the Windows version.
VERIFY --- Tells Windows whether to verify that your files are written correctly to a disk.
VOL --- Displays a disk volume label and serial number.
XCOPY --- Copies files and directory trees.
WMIC --- Displays WMI information inside interactive command shell.
3
VOLUME 1
1YourVersion.bat
PROMPT $V$G$S
2ColorCode.bat
COLOR 17
3custom.bat
COLOR 0A
TITLE Command Testing
CLS
4custom2.bat
CD "E:\3. Mine\Batch Script\Volume_1"
CLS
5twoLines.bat
@echo off
6clearFile.bat
@echo off
7sysInfo.bat
@echo off
8gather.bat
@echo off
9backup.bat
@echo off
10logIn.bat
@echo off
4
ECHO log updated
11logOut.bat
@echo off
PAUSE
12logErr.bat
@echo off
REM run command and save its error text in a temporary file
%input% 2> tempErrLog.txt
REM copy the command and its result to a permanent log file
ECHO At %time%, the command "%input%" return: >> logErr.txt
PAUSE
13mod.bat
@echo off
SET /A output = %1 %% %2
ECHO %output%
5
14divideA.bat
@echo off
SET /A output = %1 / %2
ECHO %output%
15square.bat
@echo off
SET /A output = %1 * %1
ECHO %output%
16getIP.bat
@echo off
17left10.bat
@echo off
SET string=%1
ECHO %string:~0,10%
18right10.bat
@echo off
SET string=%1
ECHO %string:~-10%
19char3.bat
@echo off
SET string=%1
ECHO %string:~2,1%
6
20trim.bat
@echo off
SET string=%1
ECHO %string: = %
21UKtoUS.bat
@echo off
SET string=%string:colour=color%
SET string=%string:flat=apartment%
PAUSE
22writer.bat
@echo off
COLOR 0D
:start
GOTO start
23reader.bat
@echo off
:start
TYPE chat.txt
TIMEOUT 3 > nul
GOTO start
24flush.bat
@echo off
25writer2.bat
@echo off
COLOR 0D
7
:start
GOTO start
26isHere.bat
@echo off
27divideB.bat
@echo off
IF %2 == 0 (
SET output=Infinity
) ELSE (
SET /A output = %1 / %2
)
ECHO %output%
28absA.bat
@echo off
SET /A output= %1 - %2
ECHO %output%
29absB.bat
@echo off
IF %1 GTR %2 (
SET /A output= %1 - %2
) ELSE (
SET /A output= %2 - %1
)
ECHO %output%
30info.bat
@echo off
ECHO.
ECHO Options:
8
ECHO 1 - Display version of Windows
ECHO 2 - Display volume details
ECHO 3 - Display name of host device
ECHO.
IF %input% == 1 VER
IF %input% == 2 VOL
IF %input% == 3 HOSTNAME
PAUSE
31info2.bat
@echo off
ECHO.
ECHO Options:
ECHO.
:choose
SET /P input= Enter a number from 1 to 3 and press enter:
IF NOT "%input:~1%" == "" ECHO Too many characters entered! & GOTO
choose
IF %input% GTR 3 ECHO Too high! & GOTO choose
IF %input% LSS 1 ECHO Too low! & GOTO choose
IF %input% == 1 VER
IF %input% == 2 VOL
IF %input% == 3 HOSTNAME
PAUSE
9
VOLUME 2
1scanLogs.bat
@echo off
MORE logs\log*.txt
PAUSE
2sortFile.bat
@echo off
3sortFileR.bat
@echo off
4mismatchTotal.bat
@echo off
FIND /I /V /C "%1" %2
5bootTime.bat
@echo off
6justOS.bat
@echo off
SYSTEMINFO | FINDSTR /B OS
7commas.bat
@echo off
PAUSE
8twoWords.bat
@echo off
PAUSE
9ending.bat
@echo off
10
FINDSTR "1$" test.txt
PAUSE
10beginning.bat
@echo off
PAUSE
11endInDigit.bat
@echo off
PAUSE
12endIn1Digit.bat
@echo off
PAUSE
13zipCode.bat
@echo off
PAUSE
14labelsOnly.bat
@echo off
:label1
:label2
PAUSE
15getCSVs.bat
@echo off
11
FINDSTR "\.csv" test.txt
PAUSE
16trickyEnd.bat
@echo off
PAUSE
17checkInput_NOTOK.bat
@echo off
:begin
PAUSE
18makeDummy.bat
@echo off
:begin
SET timeMade=%time::=%
SET timeMade=%timeMade:.=%
:case1
ECHO. > file%timeMade%.txt
GOTO begin
12
:case2
ECHO. > file%timeMade%.csv
GOTO begin
:case3
ECHO. > file%timeMade%.html
GOTO begin
==========
@echo off
Set "_var=first"
Set "_var=second" & Echo %_var% !_var!
--> first !_var!
@echo off
SETLOCAL EnableDelayedExpansion
Set "_var=first"
Set "_var=second" & Echo %_var% !_var!
--> first second
@echo off
SETLOCAL EnableDelayedExpansion
Set "_var=Old"
For /L %%G in (1,1,3) Do (
Set "_var=New"
Echo [%_var%] is now [!_var!]
)
-->
[Old] is now [New]
[Old] is now [New]
[Old] is now [New]
==========
19stringReplace.bat
@echo off
SET string=%3
SETLOCAL ENABLEDELAYEDEXPANSION
ECHO !string:%1=%2!
20makeDummy2.bat
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
SET fileType1=txt
13
SET fileType2=csv
SET fileType3=html
:begin
SET timeMade=%time::=%
SET timeMade=%timeMade:.=%
GOTO begin
21restore.bat
@echo off
DEL %1.txt
22safeRestore.bat
@echo off
23parent.bat
@echo off
CALL 22safeRestore %1
GOTO Case%errorlevel%
:Case0
ECHO File restored
EXIT /B
14
:Case1
ECHO There is no backup file to restore from
24mkdirs.bat
@echo off
GOTO Case%setup%
:CaseS
MKDIR %1
MKDIR %2
MKDIR %3
EXIT /B
:CaseW
MKDIR %1\%2\%3
25restoreDir.bat
@echo off
RMDIR /S /Q %1
MOVE %1_bak %1
26clearAll.bat
ATTRIB -r -h /D /S
27myCopy.bat
COPY test.txt folder\NewName.txt
28backup.bat
@echo off
29restoreAll.bat
@echo off
DEL *.txt
30safeRestoreAll.bat
@echo off
15
DEL *.bak
31backupDir.bat
@echo off
XCOPY /s /e /i %1 %1_bak
16
VOLUME 3
1copyToMap.bat
@echo off
COPY file1.txt Y:
SUBST /D Y:
2callLogMe.bat
@echo off
CALL 3logMe %0
PAUSE
3logMe.bat
ECHO %1 ran at %time% on %date% >> log.txt
4fileInfo.bat
@echo off
PAUSE
5doProcess.bat
@echo off
17
TITLE %0
START 6getData
TIMEOUT /T 3
DIR
PAUSE
6getData.bat
TITLE %0
HOSTNAME
DIR
PAUSE
7doProcess2.bat
@echo off
TITLE %0
DIR
PAUSE
8getData2.bat
TITLE %0
HOSTNAME
DIR
START 7doProcess2
PAUSE
9doProcess3.bat
@echo off
TITLE %0
DEL processDone.txt
DEL goAhead.txt
18
START 10getData3
:startLoop
TIMEOUT /T 3
DIR
PAUSE
10getData3.bat
TITLE %0
HOSTNAME
DIR
PAUSE
REM The 'pause' above is only for testing. You would delete it
after that.
ECHO.>goAhead.txt
PAUSE
11listServices.bat
@echo off
PAUSE
12getImageName.bat
@echo off
ECHO Delete the other columns in both files, then press enter.
19
PAUSE > nul
FC list1.csv list2.csv
PAUSE
13closeExcel.bat
@echo off
PAUSE
14raw.bat
FOR %%i IN (*.txt *.csv) DO ECHO %%i >> %%i
15list.bat
FOR %%i IN (*) DO ECHO %%i >> list.csv
16list2.bat
FOR %%i IN (*) DO ECHO %%i >> list.csv & ECHO %%i >> list.txt
17makeIPs.bat
@echo off
PAUSE
18countFiles.bat
@echo off
SET count = 0
SETLOCAL ENABLEDELAYEDEXPANSION
20
SET /A count = !count! + 1
ECHO File!count!: %%i
)
PAUSE
19top3.bat
@echo off
SET count = 0
SETLOCAL ENABLEDELAYEDEXPANSION
PAUSE
20getColumn3.bat
@echo off
PAUSE
21get1Line.bat
@echo off
REM "skip=1" means skip the first 1 line, "goto next" means get
2nd line and exit from for loop
:next
PAUSE
22getLineNum.bat
@echo off
SET /A skipVal = %1 - 1
21
FOR /F "tokens=* skip=%skipVal%" %%i IN (list2.csv) DO ECHO %%i &
GOTO next
:next
PAUSE
23getAnyLineNum.bat
@echo off
SET /A skipVal = %1 - 1
:next
PAUSE
24getValue.bat
@echo off
SET /A skipVal = %1 - 1
REM Skip that many lines, display the selected value from the next
line
:next
PAUSE
22
25reverse.bat
@echo off
PAUSE
26columnSwap.bat
FOR /F "tokens=1-3 delims=," %%i IN (list2.csv) DO ECHO
%%k,%%j,%%i >> list3.csv
DEL list3.csv
27mainReplace.bat
@echo off
PAUSE
28lineReplace.bat
@echo off
SET /P string=%*
ECHO %string%
29lineReplace1.bat
@echo off
SET /P string=%*
ECHO %string:Microsoft=Apple%
30mainReplace2.bat
@echo off
DEL temp.txt
31lineReplace2.bat
@echo off
23
SET /P string=%*
32get.bat
ECHO Parameter zero is: > %0
--> After running, now the content of the file is "Parameter zero
is: "
33get0.bat
@echo off
REM '^' escapes '>', preventing the batch file redirecting text
and overwriting itself
PAUSE
34easyShifter.bat
@echo off
SET var8 = %8
SHIFT /8
SET var9 = %8
SHIFT /8
SET var10 = %8
PAUSE
35Shifter.bat
@echo off
SET num= 8
:startLoop
SET var%num% = %8
24
SHIFT /8
SET /A num += 1
SET /A num -= 1
SETLOCAL ENABLEDELAYEDEXPANSION
PAUSE
36asterisk.bat
@echo off
25