CMD Cheat Sheet
4 minute read
Windows CMD Cheat Sheet
CMD is the default command-line interface on Windows systems.
Basic Commands
Here are some basic CMD commands:
Navigation
cd <directory>
: Change the current working directory todirectory
cd ..
: Move up one directory levelcd\
: Move to the root directorydir
: List the files and directories in the current directorydir <directory>
: List the files and directories indirectory
md <directory>
: Create a new directorydirectory
rd <directory>
: Removedirectory
(if it is empty)
File and directory management
copy <source> <destination>
: Copysource
todestination
xcopy <source> <destination>
: Copysource
and subdirectories todestination
move <source> <destination>
: Movesource
todestination
del <file>
: Deletefile
Text manipulation
type <file>
: Print the contents offile
to the terminalfind "<string>" <file>
: Search forstring
infile
findstr "<string>" <file>
: Search forstring
infile
(case-insensitive)sort <file>
: Sort the lines offile
Process management
taskkill /pid <pid>
: Terminate the process with the process IDpid
taskkill /im <process>
: Terminate all processes with the nameprocess
System information
ver
: Print the current system versionsysteminfo
: Print system informationipconfig
: Print the network configuration
Networking
ping <host>
: Send a ping request tohost
tracert <host>
: Print the route tohost
nslookup <hostname>
: Look up the DNS information forhostname
Users and groups
whoami
: Print the current usernet users
: List the users on the systemnet user <user> <password>
: Create a new useruser
with the passwordpassword
net group <group>
: Display the members ofgroup
net localgroup <group>
: Display the local groups on the system
Advanced Commands
Here are some advanced CMD commands:
Batch scripts
@echo off
: Turn off command echoing (commands will not be printed to the terminal)%0
: The name of the script%1
-%9
: The first 9 arguments passed to the script%*
: All arguments passed to the script%~dp0
: The current directory of the scriptgoto <label>
: Jump to the specifiedlabel
in the script:<label>
: Define alabel
in the scriptif <condition> <command>
: Executecommand
ifcondition
is trueif <condition> (command) else (other command)
: Executecommand
ifcondition
is true, otherwise executeother command
for <variable> in (<list>) do <command>
: Iterate throughlist
, settingvariable
to the current item and executingcommand
each timefor /f "tokens=<n>" %<variable> in (<file>) do <command>
: Readfile
line by line, settingvariable
to then
th token on each line and executingcommand
each time
Environment variables
set <variable>=<value>
: Set an environment variablevariable
tovalue
echo %<variable>%
: Print the value of the environment variablevariable
Redirection
<command> > <file>
: Redirect the output ofcommand
tofile
(overwrite)<command> >> <file>
: Redirect the output ofcommand
tofile
(append)<command> 2> <file>
: Redirect the error output ofcommand
tofile
(overwrite)<command> 2>> <file>
: Redirect the error output ofcommand
tofile
(append)
Pipes
<command1> | <command2>
: Pipe the output ofcommand1
as the input ofcommand2
Aliases
doskey <name>=<command>
: Set an aliasname
for the commandcommand
doskey /macros
: List all aliases
History
doskey /history
: List the command historydoskey <name> /history
: Display the command history for the aliasname
doskey /reinstall
: Clear the command history
I feedback.
Let me know what you think of this article on twitter @cpardue09 or leave a comment below!
Let me know what you think of this article on twitter @cpardue09 or leave a comment below!
comments powered by Disqus