Windows Command Line Cheatsheet
Sources:
- **
Overview
The Windows Command Line, or the Windows Command Prompt, is the Command Line Interface (CLI) on Tool - Microsoft Windows machines, analogous to the Terminal in Unix/Linux.
It emulates many command-line abilities in Microsoft’s deprecated text-only operating system MS-DOS (but it’s not MS-DOS).
TIP
Another name for the Windows Command Line is “cmd”.
Scripts containing Windows commands (Batch Scripts) have .bat
as the file extension. All cmd
commands are case-insensitive, so arp
and ARP
are the same.
TIP
If you need help using any command, add
/?
to it.
Cheatsheet
- Navigation
- File Management
Navigation
File Management
Command | Description |
---|---|
COPY text.txt C:\schoolwork | Copy the file text.txt to a folder with the path C:\schoolwork |
DEL text.txtERASE text.txt | Delete the file text.txt |
REN text.txt script.batRENAME text.txt script.bat | Rename a file text.txt to script.bat |
REPLACE .\src\hey.txt .\dest | Overwrite; replace a file named hey.txt in a local folder src with another hey.txt in a local folder dest , both files sharing the same name. Warning: Don’t specify .\dest\hey.txt anywhere here. |
XCOPY | Copy files and directory trees to another folder. XCOPY is similar to COPY but with additional switches to specify the source and destination paths in detail. |
XCOPY /S folder1 folder2 | Copy folders and subfolders of folder1 to folder2 |
ROBOCOPY | Robust copying of files and directories: by default, such copying only occurs if the source and destination differ in time stamps or file sizes. |
EXPAND gameData.cab | Decompresses the compressed .CAB cabinet file gameData.cab |
FC file1.ext file2.ext | Compare the contents of two files (file1.ext, file2.ext ) and display non-matching lines |
COMP file1.ext file2.ext | Compare the contents of two files (file1.ext, file2.ext ) and display non-matching items |
FIND "python" in run.bat | Output every line that contains a text string (which you must enclose in quotation marks) “python ” in the file run.bat |
FIND /C "python" in run.bat | Count every line that contains a text string (which you must enclose in quotation marks) “python ” in the file run.bat |
PRINT resume.txt | Print contents of a file resume.txt |
OPENFILES /QUERY | Query/display open files |
OPENFILES /DISCONNECT | Disconnect files opened by network users. |
TYPE test.txt | Displays the contents of the file test.txt |
TYPE playlist.m3u | SORT /unique /o C:\work\unique_play.m3u | Sort a file playlist.m3u and output only the unique values to a file C:\work\unique_play.m3u |
MORE | Display contents of one or more files, one screen at a time. |
ASSOC | Display or change the association between a file extension and a file type |
NOTEPAD | Open the Notepad application from cmd |
NOTEPAD filename.ext | Open a file filename.ext in Notepad |
Disk Management
Command | Description |
---|---|
CHKDSK | Check and repair disk problems (local disks only) |
CHKDSK /F A: | Fix errors on A: drive |
CHKDSK /R A: | Recover data on A: drive |
CHKDSK /X A: | Dismount drive A: |
CIPHER /E classified | Encrypt the folder classified |
CIPHER /D secret_recipe.txt | Decrypt the file secret_recipe.txt |
DEFRAG | Disk Defragmentation |
CHKNTFS | Display/modify disk-checking on startup |
COMPACT | Display/change the compression of files in NTFS partitions |
CONVERT | Convert FAT disk volume to NTFS |
DISKPART | Display and adjust disk partition properties |
FORMAT | Format the disk |
FSUTIL | File system management |
LABEL d:x | Rename disk D:\ to X:| |
SUBST p: c:\taxes | Assign drive P:\ to the local folder c:\taxes |
SUBST p: /D | Remove the path represented by P:| |
RECOVER d:\data.dat | Recover a file data.dat from a bad or defective disk D:| |
VOL | Display current disk volume label and serial number |
POWERCFG | Control power settings and configure Hibernate/Standby modes |
SFC /SCANNOW | Scan and update protected system files |