Skip to main content

Windows’ celebrated CLI (i.e., Command-Line Interpreter) is, without a doubt, a treasure trove of hidden features, tools, and settings. Although a bit off-putting given its lackluster GUI, Command Prompt lets you tap into every area of your Operating System, from creating new folders to formatting internal/external storage. To help you navigate cmd.exe like a pro, we’ve prepared this small, but a compressive list of Windows cmd commands. Enjoy and don’t forget to subscribe to our newsletter!

 Remarks #

This section provides an overview of what cmd is, and why a developer might want to use it.

It should also mention any large subjects within cmd, and link out to the related topics. Since the Documentation for cmd is new, you may need to create initial versions of those related topics.

Commands in CMD#

The available commands will be displayed, including a brief description, in tabular format.
In Windows 10 the following commands are listed:

CommandDescription
ASSOCDisplays or modifies file extension associations.
ATTRIBDisplays or changes file attributes.
BREAKSets or clears extended CTRL+C checking.
BCDEDITSets properties in boot database to control boot loading.
CACLSDisplays or modifies access control lists (ACLs) of files.
CALLCalls one batch program from another.
CDDisplays the name of or changes the current directory.
CHCPDisplays or sets the active code page number.
CHDIRDisplays the name of or changes the current directory.
CHKDSKChecks a disk and displays a status report.
CHKNTFSDisplays or modifies the checking of disk at boot time.
CLSClears the screen.
CMDStarts a new instance of the Windows command interpreter.
COLORSets the default console foreground and background colors.
COMPCompares the contents of two files or sets of files.
COMPACTDisplays or alters the compression of files on NTFS partitions.
CONVERTConverts FAT volumes to NTFS. You cannot convert the
current drive.
COPYCopies one or more files to another location.
DATEDisplays or sets the date.
DELDeletes one or more files.
DIRDisplays a list of files and subdirectories in a directory.
DISKPARTDisplays or configures Disk Partition properties.
DOSKEYEdits command lines, recalls Windows commands, and
creates macros.
DRIVERQUERYDisplays current device driver status and properties.
ECHODisplays messages, or turns command echoing on or off.
ENDLOCALEnds localization of environment changes in a batch file.
ERASEDeletes one or more files.
EXITQuits the CMD.EXE program (command interpreter).
FCCompares two files or sets of files, and displays the
differences between them.
FINDSearches for a text string in a file or files.
FINDSTRSearches for strings in files.
FORRuns a specified command for each file in a set of files.
FORMATFormats a disk for use with Windows.
FSUTILDisplays or configures the file system properties.
FTYPEDisplays or modifies file types used in file extension
associations.
GOTODirects the Windows command interpreter to a labeled line in
a batch program.
GPRESULTDisplays Group Policy information for machine or user.
GRAFTABLEnables Windows to display an extended character set in
graphics mode.
HELPProvides Help information for Windows commands.
ICACLSDisplay, modify, backup, or restore ACLs for files and
directories.
IFPerforms conditional processing in batch programs.
LABELCreates, changes, or deletes the volume label of a disk.
MDCreates a directory.
MKDIRCreates a directory.
MKLINKCreates Symbolic Links and Hard Links
MODEConfigures a system device.
MOREDisplays output one screen at a time.
MOVEMoves one or more files from one directory to another
directory.
OPENFILESDisplays files opened by remote users for a file share.
PATHDisplays or sets a search path for executable files.
PAUSESuspends processing of a batch file and displays a message.
POPDRestores the previous value of the current directory saved by
PUSHD.
PRINTPrints a text file.
PROMPTChanges the Windows command prompt.
PUSHDSaves the current directory then changes it.
RDRemoves a directory.
RECOVERRecovers readable information from a bad or defective disk.
REMRecords comments (remarks) in batch files or CONFIG.SYS.
RENRenames a file or files.
RENAMERenames a file or files.
REPLACEReplaces files.
RMDIRRemoves a directory.
ROBOCOPYAdvanced utility to copy files and directory trees
SETDisplays, sets, or removes Windows environment variables.
SETLOCALBegins localization of environment changes in a batch file.
SCDisplays or configures services (background processes).
SCHTASKSSchedules commands and programs to run on a computer.
SHIFTShifts the position of replaceable parameters in batch files.
SHUTDOWNAllows proper local or remote shutdown of machine.
SORTSorts input.
STARTStarts a separate window to run a specified program or command.
SUBSTAssociates a path with a drive letter.
SYSTEMINFODisplays machine specific properties and configuration.
TASKLISTDisplays all currently running tasks including services.
TASKKILLKill or stop a running process or application.
TIMEDisplays or sets the system time.
TITLESets the window title for a CMD.EXE session.
TREEGraphically displays the directory structure of a drive or
path.
TYPEDisplays the contents of a text file.
VERDisplays the Windows version.
VERIFYTells Windows whether to verify that your files are written
correctly to a disk.
VOLDisplays a disk volume label and serial number.
XCOPYCopies files and directory trees.
WMICDisplays WMI information inside interactive command shell.

To get more insight about a specific command use the /? option, e.g. the tree command gives:

tree /?

Graphically displays the folder structure of a drive or path.

TREE [drive:][path] [/F] [/A]
 
   /F   Display the names of the files in each folder.
   /A   Use ASCII instead of extended characters.
 

Features#

Microsoft Command Prompt is a command-line interpreter (CLI) for the Windows operating systems.

A CLI is program intended primarily to read operating system instructions typed on a keyboard by the user. It is therefore addressed also as a command-line interface, to contrast it with graphical interfaces.

As these interfaces (whether textual or graphical) shield the user from directly accessing to the operating system kernel, they are also said shells.

Given the name of the Command Prompt executable file, cmd.exe , the Command Prompt is friendly named cmd . Given its OS piloting role, it is also said the console.

Like other shells, cmd can read batch of instructions from a file. In this case the cmd shell acts as a language interpreter and the file content can be regarded as an actual program. When executing these batch programs, there is no intermediate compilation phase. They are typically read, interpreted and executed line by line. Since there is no compilation, there is no production of a separated executable file. For this reason the programs are denoted batch scripts or shell scripts.

Note that the instructions entered interactively might have a slightly different syntax from those submitted as a script, but the general principle is that what can be entered from the command line can be also put in a file for later reuse.

Hello World#

Command Prompt batch scripts have extension .cmd or .bat , the latter for compatibility reasons.

To create a hello-word-script, you first need a place where to type it. For simple scripts, also the Windows Notepad will do. If you are serious about shell scripting, you need more effective tools. There are anyway several free alternatives, such as Notepad++.

In your designated editor type:

echo Hello World
pause
 

Save it as hello.cmd

If you are using "Notepad" as an editor, you should pay much attention to the saved name, as Notepad tends to add always a .txt extension to your files, which means that the actual name of your file might be hello.cmd.txt . To avoid this, in the save dialog box:

  1. In the File name field enter the name in double quotes, e.g. "hello.cmd"
  2. In the Save as type field select All Files, instead of the default Text Document option.

If the file has been saved properly, its icon should be similar to (Windows Vista):

cmd icon

You may also consider to disable the option "Hide extension for known file types" in File Explorer folder view options. In this case, file names are always displayed with their extensions.

To execute hello.cmd there are two possibilities. If you are using the Windows graphical shell, just double click on its icon.

If you want to use the Command Prompt itself, you must first identify the directory where you saved hello.cmd . In this regard, if you open File Explorer with +E. In the windows listing files, you normally read the name of the directory path containing them. You can therefore identify the directory of hello.cmd . Windows directory names tend to be quite long and typing them is error prone. It is better if you select and copy the directory path in the clipboard for later pasting.

Start the Command Prompt. You read a line similar to this.

Microsoft Windows [Version ...]
(c) ... Microsoft Corporation. All rights reserved.
 
C:\Users\...>
 

The version/year of Windows of course depends on yours. In the the final line, before > , you read the path of the directory which is current. You should make current the directory where your script is. For this reason enter the change directory command cd , using a line similar to the following:

cd <dirpath>
 

Instead of <dirpath> , paste the name of the directory you previously copied.
To paste the directory path, in Windows 10, you just need to type Ctrl-C, as you would in an editor. For older systems you should be able to do this by right clicking in the cmd window.
After entering the command, note that current path, before > , changes accordingly.

You can now run your hello script by simply entering:

hello
 

Comments#

The script prints an output similar to:

C:\Users\...>echo Hello World
Hello World

C:\Users\...>pause
Press any key to continue . . .
 

The lines hosting the symbol > restate the script instructions as if you had entered interactively. This can be disabled writing:

@echo off
 

as the first line of your script. This might reduce the clutter, but you have less hints on what is going on, with respect to those script commands that do not give visible outputs.

The last command, pause , prompts you to hit any key. When you do, you exit hello .
If you run hello from the console, you don't really need it, because, when hello terminates its execution, cmd.exe remains open and you can to read hello output. When double-clicking in Explorer, you start cmd.exe for the time necessary to execute hello . When hello terminates, cmd.exe does the same and you have no possibility to read hello output. pause command prevents hello from exiting until you hit a key, which gives also the possibility to read the output.

Finally, despite the name of the script is hello.cmd , it is not necessary to type the whole name, its hello stem is sufficient. This mechanism works for executables too, with extension .exe . What if there is a script hello.cmd and an executable hello.exe in the same directory? The former has priority in the Command Prompt, so hello.cmd will be executed.

One of the most common things you'll need to do in the command prompt is navigate your file system. To do this, we'll utilize the cd and dir keywords. Start by opening up a command prompt using one of the methods mentioned here. You most likely see something similar to what's below, where UserName is your user.

C:\Users\UserName>
 

Regardless of where in your file structure you are, if your system is like most, we can start with this command:

cd C:\
 

This will change your current directory to the C:\ drive. Notice how the screen now looks like this

C:\>
 

Next, run a dir so we can see anything in the C:\ drive

dir
 

This will show you a list of files and folders with some information about them, similar to this:

dir command

There's lots of good info here, but for basic navigation, we just care about the right-most column. Notice how we have a Users folder. That means we can run this

cd Users
 

Now if you run dir again, you'll see all the files and folders in your C:\Users directory. Now, we didn't find what we wanted here, so let's go back to the parent folder. Rather than type the path to it, we can use .. to go up one folder like so

cd ..
 

Now we are back in C:\ . If you want to go up multiple folders at once, you can put a backslash and another set of periods like so: cd ..\.. , but we only needed one folder.

Now we want to look in that Program Files folder. To avoid confusing the system, it's a good idea to put quotes around the directories, especially when there are spaces in the name. So this time, we'll use this command

C:\>cd "Program Files"
 

Now you are in C:\Program Files> and a dir command now will tell you anything that's in here.

So, say we get tired of wandering around to find the folder and looked up exactly where we were needing to go. Turns out it's C:\Windows\Logs Rather than do a .. to Windows to Logs , we can just put the full path like so:

cd "C:\Windows\Logs"
 

And that's the basics of navigating the command prompt. You can now move through all your folders so you can run your other commands in the proper places.

Opening a Command Prompt#

The command prompt comes pre-installed on all Windows NT, Windows CE, OS/2 and eComStation operating systems, and exists as cmd.exe , typically located in C:\Windows\system32\cmd.exe

On Windows 7 the fastest ways to open the command prompt are:

  • Press enter image description here, type "cmd" and then press Enter.

  • Press enter image description here+R, type "cmd" then then press Enter.

It can also be opened by navigating to the executable and double-clicking on it.

In some cases you might need to run cmd with elevated permissions, in this case right click and select "Run as administrator". This can also be achieved by pressing ControlShift+Enter instead of Enter.

Comments

Popular posts from this blog

ChatGPT: The Most Advanced AI Chatbot in 2023

  ChatGPT: The Most Advanced AI Chatbot in 2022​ OpenAI release a Optimizing Language Model for Dialogue name ChatGPT on November 30, 2022.  Once it was released,  ChatGPT gained great attention and traffic, causing much discussion on online platforms. What is the magic of ChatGPT that makes people so crazy about it? In this article, we will introduce ChatGPT in detail. How to Sign Up ChatGPT? Play Unmute Loaded :  56.39% Remaining Time  - 1:19 Fullscreen Advertisement: 0:07 How to Sign Up ChatGPT? What is ChatGPT? ChatGPT is a large language model developed by  OpenAI  that can be used for natural language processing tasks such as text generation and language translation. It is based on the GPT-3.5 (Generative Pretrained Transformer 3.5) model, which is one of the largest and most advanced language models currently available. One of the key features of ChatGPT is its ability to generate human-like text responses to prompts. This makes it useful for a wide range of applications, such a

Introduction chatgpt

  Introduction Overview The OpenAI API can be applied to virtually any task that involves understanding or generating natural language or code. We offer a spectrum of  models  with different levels of power suitable for different tasks, as well as the ability to  fine-tune  your own custom models. These models can be used for everything from content generation to semantic search and classification. Key concepts We recommend completing our quickstart tutorial to get acquainted with key concepts through a hands-on, interactive example. Quickstart tutorial Learn by building a quick sample application Prompts and completions The  completions  endpoint is at the center of our API. It provides a simple interface to our models that is extremely flexible and powerful. You input some text as a  prompt , and the model will generate a text  completion  that attempts to match whatever context or pattern you gave it. For example, if you give the API the prompt, “Write a tagline for an ice cream sho

Introduction to Command Prompt: An overview of what CMD is and how it can be used.

Command Prompt, also known as CMD, is a command-line interface used in Microsoft Windows operating systems. It allows users to interact with the system by typing in commands instead of using a graphical user interface (GUI). The commands entered into CMD are executed as text-based instructions that tell the system what to do. CMD can be used to perform a wide range of tasks, such as navigating through files and folders, running programs, configuring network settings, and performing system maintenance tasks. It is often used by advanced users, system administrators, and developers who need to perform tasks that are not easily accomplished through the graphical user interface. CMD uses a specific syntax to enter commands and parameters, which can take some time to learn for those who are new to the interface. However, once mastered, CMD can be a powerful tool that can save time and increase efficiency by automating repetitive tasks and performing complex operations that are difficult to