Used in Windows for one-off commands or setting up Services or creating scripts and batch files.
Can be launched from typing cmd in the run dialogue box or from binary at C:\Windows\system32\cmd.exe.
Help
See available commands
help
Info on specific command
help <command name>
Command’s own help menu
<command name> /?
Terminal History Commands
| Key/Command | Description |
|---|---|
doskey / history | Print the session’s command history to |
| the terminal or output it to a file when | |
| specified. | |
| page up | Places the first command in session |
| history to the prompt. | |
| page down | Places the last command in history to |
| the prompt. | |
| ⇧ | Scroll up through command history. |
| ⇩ | Scroll down most recently run commands. |
| ⇒ | Types the previous command to prompt one |
| character at a time. | |
| F3 | Retypes the entire previous entry to |
| our prompt. | |
| F5 | Pressing F5 multiple times will allow |
| you to cycle through previous commands. | |
| F7 | Opens an interactive list of previous |
| commands. | |
| F9 | Enters a command to our prompt based on |
| the number specified. The number | |
| corresponds to the commands place in our | |
| history. |
Files and Directory Commands
| Command | Description |
|---|---|
dir | Lists directory contents. |
cd/chdir | Prints current working |
| directory. | |
cd/chdir <path> | Changes working directory |
to <path>. | |
tree <path> | Graphically displays the |
| directory structure from | |
<path>. | |
cls | Clears the terminal. |
md/mkdir <directory name> | Creates a directory in the |
| current working directory | |
| (or specified directory) | |
called <directory name>. | |
rm/rmdir <directory name> | Removes <directory name> |
| in the current working | |
| directory (or specified | |
| directory). | |
move [source] [destination] | Move file(s) from the |
| source folder to the | |
| destination folder. | |
copy [source] [destination] | Copy file(s) from the |
| source folder to the | |
| destination folder. Only | |
| works with files and not | |
| folders. | |
robocopy [source] [destination] | Copy files(s) and folder(s) |
| from the source folder to | |
| the destination folder. | |
more <file> | Displays the output of a |
| file or command one screen | |
| at a time. | |
<command> <PIPE> more | Displays the output of a |
| command through a <PIPE> to | |
| more. | |
type <file> | Displays the contents of a |
| file. | |
fsutil file createNew <filename> | Creates a new file with a |
| specified file name and | |
| length. | |
<length> | |
ren <existing name> <new name> | Renames <existing name> |
to <new name>. | |
del/erase <file(s)> | Deletes <files(s)>. |
Input/Output Operators
| Operator | Description |
|---|---|
[command] > [file] | Redirects the output from a |
| command into a file. | |
| Overwrites the specified | |
| files’ contents. | |
[command] >> [file] | Redirects the output from a |
| command into a file. Appends | |
| additional output without | |
| overwriting the file’s | |
| original contents. | |
[command] < [file] | Redirects the output of the |
| file and passes it into the | |
| command. | |
[command1] <pipe> [command2] | Redirects the output of the |
| first command into a “pipe” | |
| and provides it to the second | |
| command. | |
[command1] & [command2] | Executes both commands in |
| succession. It does not | |
| perform checks to see if | |
| either command passes or | |
| fails. | |
[command1] && [command2] | Checks to see if the first |
| command executes successfully | |
| and then executes the second | |
| command. If the first command | |
| fails, the current command | |
| execution halts and the | |
| second command is not | |
| executed. | |
[command1] <pipe><pipe> [command2] | Checks to see if the first |
| command fails to execute | |
| successfully and, if so, | |
| proceeds to execute the | |
| second command. |
where <pipe> is the | symbol.
Find & Filter content
| Command | Description |
|---|---|
where <file> | Displays the location of file(s) |
| provided. | |
find "example string" <file> | Searches for a string of text in a file |
| or files, and displays lines of text | |
| that contain the specified string. | |
findstr | Searches for patterns of text in files. |
| Similar to grep on Unix/Linux. | |
comp <file1> <file2> | Compares the contents of two files or |
| sets of files byte-by-byte. | |
fc <file1> <file2> | Compares two files or sets of files and |
| displays the differences between them. | |
sort | Reads input, sorts data, and writes the |
| results to the screen, a file, or | |
| another device. |
User Commands
| Commands | Description |
|---|---|
whoami | Displays the username of the currently logged-on user. |
whoami /priv | Displays the security privileges of the current user. |
whoami /groups | Displays the user groups that the current user belongs |
| to. | |
whoami /all | Displays all information about the current user, |
| including username, security identifiers (SID), | |
| privileges, and groups. | |
net user | Displays a list of the user accounts on the computer |
net localgroup | Displays the name of the server and the names of local |
| groups on the computer. | |
net group | Displays the name of a server and the names of groups |
| on the server. Only able to be used if the machine is | |
| joined to the domain. |
Networking Commands
| Command | Description |
|---|---|
ipconfig | View basic networking configurations. |
ipconfig /all | View detailed networking configuration information. |
net | CLI utility containing multiple commands to manage |
| and configure network resources. | |
net share | Displays info about all of the resources that are |
| shared on the local computer. | |
net view | Displays a list of domains, computers, or resources |
| being shared by the specified computer. | |
arp | Displays and manages the contents and entries within |
| the Address Resolution Protocol (ARP) cache. | |
netstat -an | Display current network connections. |
nslookup <query> | Query DNS for a name or address. |
Environment Variable Commands
| Command | Description |
|---|---|
%EXAMPLE_VARIABLE% | Example format for an environment |
| variable. | |
set | Prints all available environment |
| variables on the system. | |
set <%VARIABLE_NAME%> | Prints out the value of the environment |
| variable specified. It can also be used | |
| to set the variable’s value. | |
echo <%VARIABLE_NAME%> | Prints out the value of the environment |
| variable specified. It cannot make any | |
| edits to variables and will only print | |
| out the values to the console. | |
set <%VARIABLE_NAME%>=<Value> | Creates a new environment variable or |
| modifies an existing one and sets the | |
| value for the current command line | |
| session. | |
set <%VARIABLE_NAME%>= | Removes the environment variable with |
| the specified name for the current | |
| command line session. | |
setx <%VARIABLE_NAME%> <Value> | Creates a new environment variable or |
| modifies an existing one and sets the | |
| value globally by making changes to the | |
| registry. | |
setx <%VARIABLE_NAME%> "" | Removes the environment variable with |
| the specified name globally. |
Services Commands
| Command | Description |
|---|---|
sc query | Lists all running services and |
| provides additional information for | |
| each service. | |
sc query <Name> | Lists details about a specific |
| service by name. | |
sc start <Name> | Start a service by name. |
sc stop <Name> | Stop a service by name. |
| sc config <Name> start= disabled | Change settings of the service |
| specified. | |
tasklist /svc | Provide a list of services running |
| under each process on the system. | |
net start | List all running services. |
wmic service list brief | List all services on the system using |
| WMIC. Includes information such as: | |
| ExitCode, Name, ProcessID, StartMode, | |
| State, and Status. |
Task Scheduling Commands
Use schtasks, which on its own displays all tasks scheduled on the local machine.
For task scheduling management append schtasks with the following actions and perhaps their parameters:
| Action | Parameter | Description |
|---|---|---|
Query | Performs a local or remote host search to determine | |
| what scheduled tasks exist. Due to permissions, not | ||
| all tasks may be seen by a normal user. | ||
/fo | Sets formatting options. We can specify to show | |
| results in the Table, List, or CSV output. | ||
/v | Sets verbosity to on, displaying the advanced | |
| properties set in displayed tasks when used with the | ||
| List or CSV output parameter. | ||
/nh | Simplifies the output using the Table or CSV output | |
| format. This switch removes the column headers. | ||
/s | Sets the DNS name or IP address of the host we want | |
| to connect to. Localhost is the default specified. | ||
If /s is utilised, we are connecting to a remote | ||
| host and must format it as “\\host”. | ||
/u | This switch will tell schtasks to run the following | |
| command with the permission set of the user | ||
| specified. | ||
/p | Sets the password in use for command execution when | |
| we specify a user to run the task. Users must be | ||
| members of the Administrator’s group on the host (or | ||
in the domain). The u and p values are only | ||
valid when used with the s parameter. | ||
Create | Schedules a task to run. | |
/sc | Sets the schedule type. It can be by the minute, | |
| hourly, weekly, and much more. Be sure to check the | ||
| options parameters. | ||
/tn | Sets the name for the task we are building. Each | |
| task must have a unique name. | ||
/tr | Sets the trigger and task that should be run. This | |
| can be an executable, script, or batch file. | ||
/s | Specify the host to run on, much like in Query. | |
/u | Specifies the local user or domain user to utilise | |
/p | Sets the Password of the user-specified. | |
/mo | Allows us to set a modifier to run within our set | |
| schedule. For example, every 5 hours every other | ||
| day. | ||
/rl | Allows us to limit the privileges of the task. | |
| Options here are limited access and Highest. Limited | ||
| is the default value. | ||
/z | Will set the task to be deleted after completion of | |
| its actions. | ||
Change | Allows for modifying existing scheduled tasks. | |
/tn | Designates the task to change | |
/tr | Modifies the program or action that the task runs. | |
/ENABLE | Change the state of the task to Enabled. | |
/DISABLE | Change the state of the task to Disabled. | |
Delete | Remove a task from the schedule | |
/tn | Identifies the task to delete. | |
/s | Specifies the name or IP address to delete the task | |
| from. | ||
/u | Specifies the user to run the task as. | |
/p | Specifies the password to run the task as. | |
/f | Stops the confirmation warning. |