Command Prompt (cmd) Commands
The Windows command interpreter, its built-in commands and batch files.All Command Prompt (cmd) pages
- 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.
- 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.
- 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.