100% found this document useful (3 votes)
268 views11 pages

Windows Command Line Cheat Sheet

Windows Command Line Cheat Sheet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
268 views11 pages

Windows Command Line Cheat Sheet

Windows Command Line Cheat Sheet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
  • Introduction
  • Directory Navigation
  • File Management
  • Disk Management and System Information
  • Process Management
  • Batch Scripting
  • Flow Control and Shortcut Keys
  • Conclusion

Tmux Cheat Sheet

What Is the Windows Command Line?


The Windows command line (Windows command prompt) is the command-line interface
(CLI) on 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).

Methods to open the Windows CLI:


\ ● On Windows 10 or above, click Start on the bottom left corner, type cmd, and select
Command Prompt.
● On Windows 8.x or earlier, press Ctrl+R to open the Run dialog box, type cmd into
it, and press Enter.
Hence, another name for Windows CLI 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. If you need help using
any command, add /? to it, e.g., ARP /? will show the manual for ARP:
\

Directory Navigation
These commands help you view directories and move directories around.

Command Explanation
c: Change the current drive to the C:\ drive
d: Change the current drive to the D:\ drive
CD c:\path\to\my_folder Change directory to
c:\path\to\my_folder
CD .. Navigate to the parent directory of the
current working directory
CD .\new_folder Navigate to the folder new_folder located
in the current working directory
CD /D d:\videos\ Change the current drive to D:\ and access
the folder videos on it.
DIR Display files and folders in the current
directory
DIR /A c:\apps\ Display files and folders in the directory
c:\apps\
DIR /A:D Display only folders (D: directories)
DIR /A:-D Display only files (D: directories; -: not)
DIR /A:H Display hidden files and folders
DIR /O Display files and folders sorted
alphabetically
DIR /O:S Display files and folders sorted by file size
from smallest to largest
DIR /O:-S Display files and folders sorted by file size
from largest to smallest
DIR /B Display only the names of files and folders
in the current working directory
SORT Take input from a source file/pipeline, sort
its contents alphabetically (default: A to Z;
in reverse: Z to A), and display the output
SORT "C:\music\playlist.m3u" Sort the contents of
C:\music\playlist.m3u line by line
DIR /B | SORT /R /O [Link] List all file and folder names in the current
working directory, sort them in reverse
alphabetical order, and save the sorted
output to a file [Link]:
\

MOVE Move a file or files


MOVE c:\f1\[Link] c:\f2 Move a file [Link] from one folder
c:\f1 to another folder c:\f2
MD new_folder Create a new folder called new_folder in
MAKEDIR new_folder the current directory
RD new_folder Delete the folder called new_folder in the
RMDIR new_folder current directory
TREE Show the directory structure of a disk/folder
TREE "C:\Program Files" Show the directory structure of the folder
“Program Files” on the disk C:\
TREE C:\ /F Display the names of the files in each folder
in the directory structure of the C:\ drive
ATTRIB Display/set the attributes of the files in the
current directory
ATTRIB +H +S +R myItem Hide a file/folder myItem
ATTRIB -H -S -R myItem Unhide a file/folder myItem

TREE demonstration
File Management
The following commands are for managing and manipulating files.

Like Unix, cmd supports pipelines: you may pass the output of a command to the next one
by sandwiching the pipe character “|” between both.

Command Explanation
COPY [Link] C:\schoolwork Copy the file [Link] to a folder with the
path C:\schoolwork
DEL [Link] Delete the file [Link]
ERASE [Link]
REN [Link] [Link] Rename a file [Link] to [Link]
RENAME [Link] [Link]
REPLACE .\src\[Link] .\dest Overwrite; replace a file named [Link] in
a local folder src with another [Link] in
a local folder dest, both files sharing the
same name.

Warning: Don’t specify .\dest\[Link]


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 [Link] Decompresses the compressed .CAB
cabinet file [Link]
FC [Link] [Link] Compare the contents of two files
([Link], [Link]) and display
non-matching lines
COMP [Link] [Link] Compare the contents of two files
([Link], [Link]) and display
non-matching items
FIND "python" in [Link] Output every line that contains a text string
(which you must enclose in quotation
marks) "python" in the file [Link]
FIND /C "python" in [Link] Count every line that contains a text string
(which you must enclose in quotation
marks) "python" in the file [Link]
PRINT [Link] Print contents of a file [Link]
OPENFILES /QUERY Query/display open files
OPENFILES /DISCONNECT Disconnect files opened by network users.
TYPE [Link] Displays the contents of the file [Link]
TYPE playlist.m3u | SORT /unique Sort a file playlist.m3u and output only
/o C:\work\unique_play.m3u 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 [Link] Open a file [Link] in Notepad

Disk Management
It’s easy to handle and automate the following tasks on cmd.

Command Explanation
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:\[Link] Recover a file [Link] 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

System Information and Networking


The following commands are helpful in troubleshooting computers and computer networks.

Command Explanation
VER Display the current operating system
version
SYSTEMINFO List system configuration
HOSTNAME Show the computer’s hostname on the
network
DRIVERQUERY Show all installed device drivers
DATE Display/set system date
TIME Display/set system time
GPRESULT Display Resultant Set of Policy (RSoP)
information for a remote user and computer.
GPUPDATE Update group policies
IPCONFIG Display Windows IP network configurations
IPCONFIG /release Release your current local IP address
IPCONFIG /renew Request a new local IP address
IPCONFIG /flushdns Reset the contents of the DNS client
resolver cache
PING [Link] Send ICMP requests to the target
[Link] and check host availability
PATHPING Trace route and provide network latency
and packet loss for each router and link in
the path
NET Provide various network services
NET use M: \\gameServ Assign as disk M:\ the path \\gameServ,
/user:"ReadyPlayerOne" player1 logging in as “ReadyPlayerOne” and
password “player1”
TRACERT Find the IP address of any remote host
NSLOOKUP Find IP addresses on a nameserver
ROUTE Manipulate network routing tables
ROUTE PRINT Displays network route details
ARP -A List IP addresses and corresponding
physical addresses (Address Resolution
\ Protocol)
NETSH Configure network interfaces, Windows
firewall, routing, and remote access
NETSTAT Display current TCP/IP network
connections and protocol statistics
GETMAC Shows all MAC addresses of the network
adapters

Process Management
The commands below are Task Manager-like functions. Note that you call variables in
arithmetic or logical expressions by enclosing each with two “%” signs (e.g., “%a%”).

Command Explanation
SCHTASKS Create/edit a job on Task Scheduler. Use
this to create scheduled tasks in Disk
Management.
SET List environment variables
PATH Display/change the list of folders stored in
the %PATH% environment variable
SHUTDOWN /R Restart the computer
SHUTDOWN /S /T 60 Shut down the computer 60 seconds from
now
TASKLIST List running tasks
TASKLIST /SVC Show services related to each task
TASKLIST /V Display detailed task information
TASKLIST | FIND "1234" Get the name of the executable associated
with the process ID (PID) of 1234
TASKKILL End one or more tasks
TASKKILL /IM "[Link]" Terminate all Microsoft Edge instances:

TASKKILL /PID 10736 Terminate process with PID of 10736


REG Registry Editor
REGEDIT
RUNAS /USER:user2 program1 Execute a program program1 as another
user user2
POWERSHELL Open a Powershell instance

Batch Scripting
These commands are for constructing and debugging batch scripts (.bat). To suppress the
output of a certain command, add @ in front of it, e.g., @echo off.

Demonstration of CHOICE, PAUSE, and TIMEOUT

Command Explanation
REM comment. . . Prefix for the single-line comment
:comment. . . “comment. . .”
GOTO end Format of multi-line comments represented
<comment_block> by <comment_block> enclosed by
:end delimiters end and :end
SET /A c = %a% + %b% Assign the arithmetic expression a+b to the
variable c
^ Escape character
some_command > [Link] Redirect output of some_command to a file
[Link]
? Wildcard representing one character
* Wildcard representing multiple characters
& Introduce a new command on the same line
TIMEOUT 3600 Tell the command prompt to sleep for 3600
seconds (= 1 hour)
PAUSE Prompt the user to continue
CHOICE Prompt the user to pick an on-screen option
CHOICE /T 15 /C ync /CS /D y /M You have 15 seconds to press Y, N, or C
"Press y=Yes, n=No, c=cancel:" keys without capitalization, defaulting to “y”
if time runs out without a decision
CLS Clear screen
CMD Restarts Windows command prompt
window:

COLOR Set text and background color of cmd:


\

ECHO ON Display each command executed


ECHO OFF Only display command output
ECHO a string of characters Display a string of characters
HELP Display help
PROMPT topSecret^>$$ Changes the command line prompt to
topSecret>$ for the current session
PROMPT Reset the command line prompt to default
START X Start/open a program/document X in a new
window
TITLE top Secret Set the title of the current session of
Windows command prompt to top Secret
/? Add this to the end of any command word
(shown in ALL CAPS in this cheat sheet) to
get help on the command, e.g., CD/? =
manual for CD (change directory) command
| CLIP Append this to the end of a command to
copy the command output to the clipboard
EXIT Exits the command line

Flow Control
Note the condition is a Boolean expression e.g., %a%==5.

Conditional Syntax
If IF (condition) do_something
If-else If (condition) (do_something)
ELSE (do_something_else)
Nested if IF (condition1) IF (condition2)
do_something
Infinite loop :marker
do_something
GOTO marker
While loop :marker
\ IF (condition) (
do_something
GOTO :marker
)

Shortcut keys
Any Windows CLI cheat sheet must include methods to speed up your work, such as the
following.

Key Effect
Tab Autocomplete
Ctrl+F Find text in console (opens dialog box)
F1, F3, F5, F8 Retype command
F2 Copy the current command leftward of the
cursor
F4 Delete the current command rightward of
the cursor
F6 Insert end-of-file character
F7 List previous commands from which you
choose
F9 Retype a command by typing its line
number in the command history
Conclusion
We sincerely hope this Windows cmd commands cheat sheet helps you finish your work
quickly and efficiently today, especially if you’re prone to confusing Windows command
prompt commands with other terminal scripting languages in the past.

Remember to check out our course offerings on Windows.

Common questions

Powered by AI

XCOPY and ROBOCOPY are preferable over COPY when handling complex directory structures or ensuring efficient copying operations. XCOPY supports copying multiple files and directory trees with more options such as filtering and depth control . ROBOCOPY offers robust capabilities—copying only when timestamp or file size differences are detected—making it ideal for backup operations or mirroring directories where consistency and minimal impact on resources are necessary .

The Windows Command Line serves as the CLI for Microsoft Windows, emulating many of the abilities from Microsoft's former text-only operating system, MS-DOS, although it is not MS-DOS itself . Conversely, the Unix/Linux Terminal provides a CLI that is rooted in the Unix operating system, focusing strongly on a multiuser environment and rich scripting capabilities . Windows CLI commands are case-insensitive, while Unix/Linux commands are case-sensitive, revealing different design philosophies influenced by their respective operating systems backgrounds.

Using the MOVE command in a Windows-based system effectively shifts a file from one directory to another without creating a copy, thereby reorganizing the file system and freeing up space in the source directory . This command not only aids in maintaining a tidy file structure but also helps in managing storage resources efficiently, as files do not need to be replicated.

The DIR command in Windows Command Line facilitates directory navigation and management by enabling users to display files and folders in the current directory with various sorting options like alphabetical order (DIR /O), by size (DIR /O:S), and displaying only files or directories (DIR /A:-D, DIR /A:D). Such features allow users to tailor their directory view according to specific needs, improving navigation efficiency by focusing on desired file types or attributes, such as hidden files via DIR /A:H .

Batch scripts in Windows Command Line provide the advantage of automating repetitive tasks, reducing manual input, and minimizing human error . They offer the capability to execute multiple commands sequentially, facilitate comments and flow control with GOTO and conditional syntax, and utilize built-in loops such as IF and WHILE to process complex logic structures. This enhances productivity and ensures consistency in environment operations.

IPConfig commands aid in troubleshooting network issues on Windows systems by displaying current IP network configurations (IPCONFIG), releasing and renewing the local IP address (IPCONFIG /release, IPCONFIG /renew), and resetting the DNS client resolver cache (IPCONFIG /flushdns). These functions help diagnose and resolve connectivity issues by allowing users to manage and refresh their networking settings, contributing to networking stability and performance.

POWERSHELL significantly enhances Windows Command Line capabilities by providing a comprehensive scripting language and automation framework that can manage intricate system configurations and perform complex task operations . It extends command functionality beyond traditional CLI tasks, offering object-oriented scripting and robust administrative tools, thus addressing more sophisticated system management needs compared to basic command capabilities in native cmd environments.

TASKLIST and TASKKILL are complementary commands for process management. TASKLIST allows users to view active processes along with details such as process ID (PID) and service association, enabling users to identify which processes consume resources . TASKKILL, on the other hand, is used to terminate one or more tasks based on criteria like process ID or executable image name (e.g., /PID or /IM). Together, they enable comprehensive control over running processes by combining monitoring and terminating capabilities.

Efficient disk use and management in the Windows Command Line can be achieved through commands such as CHKDSK to check and repair disk errors, DEFRAG for defragmentation, and DISKPART to handle partition properties . Additionally, using commands like COMPACT to control file compression, FORMAT to prepare new disks, and CIPHER to encrypt directories enhance both the organization and security of disk resources, optimizing available storage .

The TREE command expands upon basic directory viewing by providing a hierarchical visualization of directory structures, highlighting how directories and their contents relate to each other across different levels . While DIR displays directory contents on a single level, TREE outputs a complete tree view, helping users understand the architecture and organization of files across multiple depths in the directory system. It can also include file names with the /F switch, adding more context .

 
 
 
 
 
 
 
 
 
 
 
 
 
 
What Is the Windows Command Line? 
The Windows command line (Windows command prompt) is the comm
 
 
 
 
 
 
 
 
 
Directory Navigation 
These commands help you view directories and move directories around. 
 
Command 
Ex
 
 
 
 
 
 
CD .
ew_folder 
Navigate to the folder new_folder located 
in the current working directory 
CD /D d:videos
 
 
 
 
 
 
in the directory structure of the C: drive 
ATTRIB 
Display/set the attributes of the files in the 
current dir
 
 
 
 
 
 
File Management 
The following commands are for managing and manipulating files. 
 
Like Unix, (https://www.stat
 
 
 
 
 
 
TYPE playlist.m3u | SORT /unique 
/o C:workunique_play.m3u 
Sort a file playlist.m3u and output only 
the uniq
 
 
 
 
 
 
HOSTNAME 
Show the computer’s hostname on the 
network 
DRIVERQUERY 
Show all installed device drivers 
DATE 
Di
 
 
 
 
 
 
TASKLIST /SVC 
Show services related to each task 
TASKLIST /V 
Display detailed task information 
TASKLIST | FI
 
 
 
 
 
 
^ 
Escape character 
some_command > output.txt 
Redirect output of some_command to a file 
output.txt 
? 
Wildca
 
 
 
 
 
 
PROMPT 
Reset the command line prompt to default 
START X 
Start/open a program/document X in a new 
window 
TIT

You might also like