Command Prompt (cmd)
The Windows command interpreter, its built-in commands and batch files.
Official documentation- cmd: Access is denied.Access is denied in cmd is Windows error 5: the file is read-only, NTFS permissions do not allow it, or the command needs an elevated Command Prompt to run.
- The process cannot access the file because it is being used by another process.Windows error 32: another program holds the file open without sharing. Find it with Resource Monitor or handle.exe, close it, then retry the del, move or copy.
- 'x' is not recognized as an internal or external command, operable program or batch file.cmd prints this when the name you typed is not a built-in command and no matching .exe, .cmd or .bat exists in the current folder or any PATH directory.
- The filename, directory name, or volume label syntax is incorrect.Windows error 123: the path contains a character Windows forbids in names, such as < > | ? * or a stray colon or quote, often from a pasted path or a date.
- cmd: The syntax of the command is incorrect.The syntax of the command is incorrect means cmd could not parse a line: usually an empty variable in an if test, unbalanced parentheses or a bad for loop.
- cmd: The system cannot find the file specified.Windows error 2 means the folder exists but the file does not: a typo, a hidden extension like report.txt.txt, the wrong current folder or an unquoted path.
- cmd: The system cannot find the path specified.cmd prints The system cannot find the path specified when a folder in the path is missing, a path with spaces is unquoted, or AutoRun names a bad path.
- timeout: ERROR: Input redirection is not supported, exiting the process immediately.timeout.exe exits at once when its input is redirected, as in CI jobs, scheduled tasks and pipes. Wait with ping -n or PowerShell Start-Sleep instead.
- cmd: ... was unexpected at this time.cmd prints X was unexpected at this time when a line breaks after expansion: an empty variable in if, %i instead of %%i in a batch for loop, or a ) in a value.
- Check %ERRORLEVEL% in a batch file (if errorlevel, ||, exit /b)Read a command's exit code in cmd with %ERRORLEVEL%, test it with if errorlevel N (true for N or higher) or && and ||, and return a code with exit /b N.
- findstr: search text in files from cmd (the Windows grep)findstr searches files or piped output for text: /i ignores case, /n shows line numbers, /s recurses, /c: matches a phrase, /r uses its limited regex syntax.
- for /f in cmd: read a file line by line or capture a command's outputfor /f loops over the lines of a file, a string or a command's output and splits them with tokens and delims. Use %%a in batch files and usebackq for spaces.
- Add a folder to PATH in cmd: set PATH for the session, setx or System Propertiesset PATH=folder;%PATH% changes PATH only for the current cmd window. Make it permanent in System Properties; setx truncates values longer than 1024 characters.
- sfc /scannow and DISM /RestoreHealth: repair Windows system filesRun DISM /Online /Cleanup-Image /RestoreHealth first to repair the component store, then sfc /scannow to fix protected system files, both in an elevated prompt.
- where: find which executable runs for a command in Windows (like which)where name lists every match in the current folder and PATH in search order, and the first one is what cmd runs. In PowerShell type where.exe instead.
- cmd /c vs cmd /k: run a command and exit, or keep the window opencmd /c runs a command and exits with its exit code; cmd /k keeps the window open. Tested: exit codes, chaining with && and &, /v:on and quote-stripping rules.
- robocopy /MIR: mirror a folder (and why it deletes files in the destination)robocopy /MIR mirrors a folder: it copies subfolders and deletes destination files missing from the source. Preview with /L, exit codes 1-3 and /E /PURGE.
- set /p: read user input or the first line of a file in a batch fileset /p VAR=Prompt waits for a line of input and stores it in VAR. With < file it reads the first line. Empty input leaves VAR unchanged and sets errorlevel 1.
- setlocal enabledelayedexpansion: why variables do not change inside a for loopcmd expands %VAR% once per line or parenthesised block, so loops see old values. setlocal enabledelayedexpansion adds !VAR!, which is read each time it runs.