Want to speed up your Windows system, fix common errors, or perform routine maintenance? The Command Prompt—often overlooked—holds a wealth of essential commands for system administration, troubleshooting, and optimization. Here’s what you’ll get: a concise set of must-know commands, step-by-step usage for key tasks, real-world examples, common pitfalls, and how to resolve issues when things go wrong.
What You'll Need
- A Windows PC with administrative privileges (right-click Start > Run as administrator)
- Command Prompt (accessed via Start menu or by pressing Win + R, typing `cmd`, and hitting Enter)
- Basic familiarity with typing commands (some commands require spaces or specific format)
Step-by-Step: Essential Command Prompt Commands
- Check Windows Version and Build
Verify your Windows edition and version number to confirm compatibility for commands or updates.
Command: `ver` (displays Windows version) and `wmic os get caption, version` (full details).
Example Output:
Microsoft Windows [Version 10.0.19045]Copyright (c) 2022 Microsoft Corporation. All rights reserved.Note: This helps ensure commands like `wmic` or `diskpart` work correctly.
- Free Up Disk Space
Quickly identify large files or folders consuming space.
Command: `df -h` (shows disk usage) or `wmic OS GET FreePhysicalMemory, TotalVisibleMemorySize` (for RAM). For specific drive, use `df /v` or `fsutil volume diskfree D:` (replace D: with your drive letter).
Example Output:
Filesystem 1K Blocks Used Available Use% Mounted on /dev/sda1 46567200 2345600 22108600 53% / /dev/sdb1 4194304 10240 4091884 3% /mnt/disk2Action: Delete junk files with `cleanmgr` (Windows Cleaner) or `fsutil` for folder cleanup.
- Check Running Processes
Stop or kill unresponsive processes.
Command:** `tasklist` (lists all processes) and `taskkill /IM
.exe /F` (force-stop a process). Example:
taskkill /IM chrome.exe /F(closes Chrome if it’s stuck).Caution: Running `taskkill` without the `/F` flag may not kill the process—always use `/F` for critical apps.
- Scan for Malware
Run a basic scan for malware or suspicious activity.
Command:** `malwarebytes` (if installed via setup) or use Windows Defender with `Windows Security > Virus & Threat Protection > Quick Scan`. For CLI-based detection, use `sc query` to check running services or `wmic product get name, version` to check installed software.
- Restart Services
Restart critical services like Windows Update or DNS.
Command:** `sc stop
&& sc start ` (replace ` ` with service names like `wuauserv` or `dns_svc`). List services with `sc query`. Example:
sc stop wuauserv && sc start wuauserv(restarts Windows Update). - Check Network Connectivity
Diagnose slow or unresponsive internet.
Commands:
ping google.com(checks DNS resolution)ipconfig /all(shows adapter details)netsh int ip reset(resets IPv4/IPv6 settings).Troubleshoot with:
arp -a(checks cached addresses)tracert google.com(tests route to a site). - Backup Important Files
Use `robocopy` to create a compressed backup of critical folders.
Command:** `robocopy C:\Data D:\Backup\Data /E /COPYALL /R:1 /W:1 /LOG:backup.log`
Flags Explained:**
- /E – Includes subfolders (even empty ones)
- /COPYALL – Copies files and attributes
- /R:1 – Retries once if a file can’t be copied
- /W:1 – Waits 1 second between retries
- /LOG – Saves a log file for troubleshooting
Note:** Only use this on non-system drives (e.g., D:).
- Update Windows System Files
Force a system file check and update.
Commands:**
sfc /scannow(scans and replaces corrupted files)DISM /Online /Cleanup-Image /RestoreHealth(repairs Windows Image).Run both commands in one session and reboot after completion.
- Optimize Disk Performance
Defrag or optimize disk settings for speed.
Command:** `defrrag C:` (defragments the C: drive) or `fsutil behavior set disabledeferwriteflushing 0` (prevents write delays).
- Clean Up Temporary Files
Remove temporary files that clutter disk space.
Command:** `cleanmgr` (run from Start > All Apps > Windows Administrative Tools > System). For CLI cleanup, use `del /f /q %temp%\*.*` (deletes all files in %temp%).
Warning:** This may delete cached files needed for apps. Use `cleanmgr` for safer removal.
Common Mistakes
- Running commands without admin rights.
Many commands (e.g., `defrrag`, `sfc`) require admin privileges. Always open Command Prompt as Administrator.
- Using wildcards incorrectly.
Commands like `del *.*` deletes everything in the folder. Use `/S` for subfolders and `/Q` for quiet mode (no confirmation).
- Overwriting system files.
Commands like `sfc /scannow` should only run in a clean session. Avoid running them during active system use.
- Ignoring path errors.
If a command fails with "File not found," double-check the drive or folder path (e.g., `C:\Windows\` vs. `C:\`).
Tips
- Use shortcuts for repeated tasks.
Create a `.bat` file to group commands (e.g., `@echo off & sfc /scannow & dism /online /cleanup-image /restorehealth`).
- Enable command history.
Type `setx cmdhistory 1000` to increase history (up to 1000 entries).
- Backup before major operations.
Commands like `robocopy` or `del` can’t be undone. Test in a non-critical folder first.
- Learn keyboard shortcuts.
Use `Ctrl+Shift+V` to paste from Clipboard, and `Ctrl+R` to repeat the last command.
Troubleshooting
If a command fails, start with these checks:
- Restart your PC.
Sometimes, a simple reboot resolves temporary glitches.
- Update Windows and drivers.
Run `systeminfo` to check for pending updates. Update drivers via Device Manager (Right-click Start > Device Manager > Update driver).
- Check for permission errors.
If a command like `defrrag` fails, try running it in an elevated Command Prompt.
- Reinstall the app or service.
For stubborn issues (e.g., `wuauserv` not starting), uninstall and reinstall the service via `sc delete wuauserv` followed by `sc start wuauserv`.
- Use a different command.
If `robocopy` fails, try `xcopy` for simpler transfers. Example:
xcopy C:\Data D:\Backup\Data /E /C /H /IFlags here mirror `/COPYALL`, `/E`, and `/S`.
Frequently Asked Questions
1. Why does `taskkill` not kill the process?
If `taskkill` fails, the process may be locked by another program (e.g., antivirus). Try force-killing it from Task Manager (Right-click Task Manager > More details > End Task). Alternatively, use `taskkill /F /IM
2. How do I restore deleted files using Command Prompt?
Command Prompt cannot restore deleted files directly. Use tools like `Recuva` or `EaseUS` (free versions available). For system files, run `sfc /scannow` to repair corrupted file references.
3. Can I use Command Prompt to reset a forgotten Windows password?
No. For password resets, you must boot into Safe Mode or use a recovery USB. Command Prompt alone cannot modify user passwords.
4. What if `robocopy` creates infinite loops?
Infinite loops in `robocopy` often happen with shared folders or network paths. Add `/DCOPY:A` to copy only attributes (not files) to avoid endless retries. Example:
robocopy D:\Source E:\Destination /E /DCOPY:A /LOG:backup.log
5. Why does `sfc /scannow` take so long?
`sfc` scans all protected system files, which can take 15–30 minutes. If it hangs, wait or restart the PC. For faster results, run it during low-system-usage periods.
6. How do I check if Command Prompt is blocked by antivirus?
Temporarily disable antivirus software (e.g., Windows Defender real-time protection) and retry commands. If commands fail despite no other issues, your AV may block admin tasks. Exceptions can be set in antivirus settings for the command file.