|
help commandName
|
|
commandName /?
|
|
help --> show all system commands
|
|
help
|
|
Clear Screen
|
cls
|
|
Tab
|
Autocomplete
|
|
arrow keys up/down
|
back/forward history commands
|
|
Control + C
|
stops current command
|
|
ALT + F7
|
clears the history
|
|
F7
|
shows the history
|
|
mkdir
subdirectory |
creates new subdirectory
|
|
mkdir subdir/subsubdir
|
creates subdir & subdir/subsubdir
Hint: creates it, if they aren't existing |
|
rmdir
|
removes an empty dir
|
|
rmdir /s directory
|
removes directory with content
|
|
rmdir /s /q directory
|
removes directory with content & skips y/n question
|
|
copy src dst
|
copy files
|
|
copy /Y src dest
|
copy files overwrites without quesiton
|
|
xcopy /s src dest
|
copies dirs and subdirs except empty ones
|
|
xcopy /YS src dest
|
as above without ask to overwrite
|
|
xcopy /YS src \\server\share
|
copy to network share
|
|
robocopy /S src dest
|
copies dirs and subdirs except empty ones
|
|
robocopy /YS src dest
|
as above without ask to overwrite
|
|
%0
|
Name of Script
|
|
%1 ... %9
|
Parameter 1 ... Parameter 9
|
|
%*
|
prints all parameters as a string
|
|
(one line)
for %%x in (%*) do echo %%x |
access it through a for loop works with > 10 parameters
|
|
parameters_script.bat
|
@echo off
call parameters_subscript.bat %* EXIT /B %errorlevel% |
|
parameters_subscript.bat
|
@ECHO off
echo subscript called with %* EXIT /B 0 |
|
set array[0]=0
set array[1]=1 ... |
set value to a specific array element
|
|
echo %array[0]%
echo %array[1]% |
access to array elements
|
|
missing loop over elements: indexed
|
|
|
echo "Hi:"
goto :good |
|
:bad
echo "I don't like scripting" goto :eof |
|
:good
echo "I like scripting" goto :eof |
|
realative
|
parent directory
|
cd .., cd..
|
|
subdirectory
|
cd subdirectoy
|
|
|
absolute
|
cd C:\Windows
|
|
|
cd \Windows
|
||
|
change drive
|
Z:
|
|
|
? (file?.txt)
|
one arbitary character
|
|
* ( *.bat)
|
arbitary characters (0,1 or more)
|
|
type file
|
show file content
|
|
more
|
show file content pagewise
|
|
sort file
|
show file content sorted
|
|
current folder
|
dir
|
|
absolute path
|
dir C:\Windows
|
|
dir Y:
|
different drive
|
|
dir /B
|
only show file names and directory names
|
|
@ echo off
set /P name="Input yor name: " |
Syntax: set /P var=prompt:
|
|
echo Hi %name%
|
variable call
|
|
@echo off
echo Bill > file echo Gate >> file |
|
|
set /P filecontent =< file
echo First Line: %filecontent% |
set /P var=< file
|
|
FOR /f %%f in (file) Do (
echo %%f ) |
REM print each line in file
|
|
setlocal
set MY_ENV=abc endlocal |
Only active in the current batch file (local)
|
|
set MY_ENV=abc
|
creates or changes an environment variable that is active in the cmd. (global)
|
|
set
|
shows the active environment variables
|
|
echo %USERNAME%
|
print variable out
|
|
defined MY_VAR
|
returns
0 => Execution was successful >0 => Execution failed |
|
IF test (command) ELSE (command)
|
Syntax
|
|
for {%%|%}<Variable> in (<Set>) do <Command> [<CommandLineOptions>]
|
|
cmd.exe use ->%
|
|
batch script use ->%%
|
|
call :print_name Florian
|
|
echo print_name exitst with %errorlevel%
|
|
goto :eof
|
|
:printname
echo Hit %1 exit /B 0 <- REM sets exit status of :print_name |
|
rename file1 file2
|
renamef filte1 to file2
|
|
move file1 dir
|
move file 1 to dir (path dir/file1)
|
|
move file1 dir/file2
|
moves and renames file1 to file2 (path: dir/file2) file2 is overwritten from file1
|
|
move /Y file1 file2
|
moves and overwrites file1 to file2 without asking
|
|
Case-Insensitive
|
|
Max. 260 characters incl. invisible terminating null character
|
|
spaces and character set 128 - 255 allowed
|
|
Never <, >, :, ", /, \, |, ?, *
|
|
Hint: A-Z, a-z, 0-9, _, spaces, ( underscore as space )
|
|
*.bat & *.cmd
|
|
dir /B --> only show file names and directory Names
|
|
rename dir1 dir2
|
renames dir1 in dir2
|
|
move dir1 dir2
|
if dir2 exist: dir1 into dir2 (path: dir2/dir1), else rename dir1 to dir2
|
|
move file1 dir/file2
|
file 2 is deleted. file1 get the name of file2 ans is set at the position of file2 with asking (Yes/No/All)
|
|
move /Y file1 file2
|
file 2 is deleted. file1 get the name of file2 ans is set at the position of file2 without asking.
|
|
type file.txt | sort
|
give output of type to sort
|
|
sort < file.txt
|
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
|
redirects errors(stderr) ro errors.txt
|
|
rm file 2> NUL
|
discard errors
|
|
rm file 2>&1
|
redirect stderr to stdout
|
|
echo "you" >> file.txt
|
append "you" to file.txt
|
|
REM
|
Präfix after them the text
|
|
set /a i=0
echo i=%i% |
|
set /a i=1+1 Operatoren +, -, *, /
|
|
set /a i+=1 Operatoren +, -, *, /
|
|
set array=1 2 3 4
|
|
|
%array%
|
(echo) all Array elements
|
|
for %%a in (%array%) do (
echo%%a ) |
loop over elements
|
|
set array=(and nothing else)
|
unset variable or array
|
|
Operator
|
Info
|
Equal
|
|
EQU
|
==
|
Equal
|
|
NEQ
|
!=
|
Not equal
|
|
LSS
|
<
|
Less
|
|
LEQ
|
<=
|
Less than or equal to
|
|
GTR
|
>
|
Greater than
|
|
GEQ
|
>=
|
Greater than or equal
|
|
NOT
|
!
|
Not
|
|
Notepad
|
|
Notepad++
|
|
VisualStudioCode
|
|
Notepad
|
|
Notepad++
|
|
VisualStudioCode
|
|
Atom
|
|
cmd.exe
|
|
Windows Terminal
|
|
ConEmu
|
|
cmder
|
|
Specify exit code:
|
echo "abc"
exit 0 |
|
Query error level
|
echo %ERRORLEVEL%
|
|
Exit/Return codes
|
0 => Execution was successful
>0 => Execution fiales with code X |
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.