The 30 most useful Command Prompt commands for editing files and managing your PC
- Command Prompt commands let you manage your computer just by typing.
- Some Command Prompt commands let you move files, while others let you change your internet settings.
- Here are some of the most useful Command Prompt commands, and what they do.
- Visit Insider's Tech Reference library for more stories.
The Command Prompt isn't pretty, but it's one of the most powerful apps on your PC. With it, you can move or delete files, change your Wi-Fi settings, lock your hard drive, and even shut down the computer.
But to use Command Prompt, you'll need to know the commands for it. Here are some of the most useful commands, along with explanations of what they'll do.
The essential Command Prompt commands
We'll sort these commands into a few different groups, based on what they're used for.
Important: This is a list of base commands, some of which will work right away, some of which only work in specific situations, and most of which will only work if you add more text or commands afterwards.
It would be impossible to list every use case for each command, so if a certain command doesn't work right away, carefully read the error that Command Prompt gives you or do more research online for your specific use case. You can also type the command and then add a space and /? for examples of how to use it.
Managing your apps
Editor & Staff Writer for Tech Reference
15 Windows Command Prompt (CMD) Commands You Must Know
The command prompt is slowly disappearing from the Windows interface and for good reasons: CMD commands are an antiquated and mostly unnecessary tool from an era of text-based input. But many commands remain useful, and Windows 8 and 10 even added new features.
Here we present the essential commands every Windows user must know.
Not sure how to access the Windows command prompt, forgot basic Windows commands, or would like to know how to see a list of switches for each command (aka prompt codes)? Refer to our beginners guide to the Windows command line for instructions.
Windows Command Prompt Commands
If you haven't poked around inside Windows' command line, you're missing out. There are lots of handy tools you can use if you know the correct things to type.
Most files in Windows are associated with a specific program that is assigned to open the file by default. At times, remembering these associations can become confusing. You can remind yourself by entering the command assoc to display a full list of filename extensions and program associations.
You can also extend the command to change file associations. For example, assoc .txt= will change the file association for text files to whatever program you enter after the equal sign. The assoc command itself will reveal both the extension names and program names, which will help you properly use this command.
In Windows 10, you can view a more user-friendly interface that also lets you change file type associations on the spot. Head to Settings (Windows + I) > Apps > Default apps > Choose default app by file type.
Deleting files on a mechanical hard drive doesn't really delete them at all. Instead, it marks the files as no longer accessible and the space they took up as free. The files remain recoverable until the system overwrites them with new data, which can take some time.
The cipher command, however, wipes a directory by writing random data to it. To wipe your C drive, for example, you'd use the cipher /w:d command, which will wipe free space on the drive. The command does not overwrite undeleted data, so you will not wipe out the files you need by running this command.
You can use a host of other cipher commands, however, they are generally redundant with BitLocker enabled versions of Windows.
Drivers remain among the most important software installed on a PC. Improperly configured, missing, or old drivers in Windows can cause all sorts of trouble, so it's good to have access to a list of what's on your PC.
That's exactly what the driverquery command does. You can extend it to driverquery -v to obtain more information, including the directory in which the driver is installed.
4. File Compare
You can use this command to identify differences in text between two files. It's particularly useful for writers and programmers trying to find small changes between two versions of a file. Simply type fc and then the directory path and file name of the two files you want to compare.
You can also extend the command in several ways. Typing /b compares only binary output, /c disregards the case of text in the comparison, and /l only compares ASCII text.
So, for example, you could use the following:
The above command compares ASCII text in two Word documents.
This command relays the IP address that your computer is currently using. However, if you're behind a router (like most computers today), you'll instead receive the local network address of the router.
Still, ipconfig is useful because of its extensions. ipconfig /release followed by ipconfig /renew can force your Windows PC into asking for a new IP address, which is useful if your computer claims one isn't available. You can also use ipconfig /flushdns to refresh your DNS address. These commands are great if the Windows network troubleshooter chokes, which does happen on occasion.
Entering the command netstat -an will provide you with a list of currently open ports and related IP addresses. This command will also tell you what state the port is in; listening, established, or closed.
This is a great command for when you're trying to troubleshoot devices connected to your PC or when you fear a Trojan infected your system and you're trying to locate a malicious connection.
Sometimes, you need to know whether or not packets are making it to a specific networked device. That's where ping comes in handy.
Typing ping followed by an IP address or web domain will send a series of test packets to the specified address. If they arrive and are returned, you know the device is capable of communicating with your PC; if it fails, you know that there's something blocking communication between the device and your computer. This can help you decide if the root of the issue is an improper configuration or a failure of network hardware.
This is a more advanced version of ping that's useful if there are multiple routers between your PC and the device you're testing. Like ping, you use this command by typing pathping followed by the IP address, but unlike ping, pathping also relays some information about the route the test packets take.
The tracert command is similar to pathping. Once again, type tracert followed by the IP address or domain you'd like to trace. You'll receive information about each step in the route between your PC and the target. Unlike pathping, however, tracert also tracks how much time (in milliseconds) each hop between servers or devices takes.
Powercfg is a very powerful command for managing and tracking how your computer uses energy. You can use the command powercfg hibernate on and powercfg hibernate off to manage hibernation, and you can also use the command powercfg /a to view the power-saving states currently available on your PC.
Another useful command is powercfg /devicequery s1_supported, which displays a list of devices on your computer that support connected standby. When enabled, you can use these devices to bring your computer out of standby, even remotely.
You can enable this by selecting the device in Device Manager, opening its properties, going to the Power Management tab, and then checking the Allow this device to wake the computer box.
Powercfg /lastwake will show you what device last woke your PC from a sleep state. You can use this command to troubleshoot your PC if it seems to wake from sleep at random.
You can use the powercfg /energy command to build a detailed power consumption report for your PC. The report saves to the directory indicated after the command finishes.
This report will let you know of any system faults that might increase power consumption, like devices blocking certain sleep modes, or poorly configured to respond to your power management settings.
Windows 8 added powercfg /batteryreport, which provides a detailed analysis of battery use, if applicable. Normally output to your Windows user directory, the report provides details about the time and length of charge and discharge cycles, lifetime average battery life, and estimated battery capacity.
Windows 8 introduced the shutdown command that, you guessed it, shuts down your computer.
This is, of course, redundant with the already easily accessed shutdown button, but what's not redundant is the shutdown /r /o command, which restarts your PC and launches the Advanced Start Options menu, which is where you can access Safe Mode and Windows recovery utilities. This is useful if you want to restart your computer for troubleshooting purposes.
This command will give you a detailed configuration overview of your computer. The list covers your operating system and hardware. For example, you can look up the original Windows installation date, the last boot time, your BIOS version, total and available memory, installed hotfixes, network card configurations, and more.
Use systeminfo /s followed by the hostname of a computer on your local network, to remotely grab the information for that system. This may require additional syntax elements for the domain, user name, and password, like this:
13. System File Checker
System File Checker is an automatic scan and repair tool that focuses on Windows system files.
You will need to run the command prompt with administrator privileges and enter the command sfc /scannow. If SFC finds any corrupt or missing files, it will automatically replace them using cached copies kept by Windows for this purpose alone. The command can require a half-hour to run on older notebooks.
You can use the tasklist command to provide a current list of all tasks running on your PC. Though somewhat redundant with Task Manager, the command may sometimes find tasks hidden from view in that utility.
There's also a wide range of modifiers. Tasklist -svc shows services related to each task, use tasklist -v to obtain more detail on each task, and tasklist -m will locate DLL files associated with active tasks. These commands are useful for advanced troubleshooting.
Our reader Eric noted that you can "get the name of the executable associated with the particular process ID you're interested in." The command for that operation is tasklist | find [process id].
Tasks that appear in the tasklist command will have an executable and process ID (a four- or five-digit number) associated with them. You can force stop a program using taskkill -im followed by the executable's name, or taskkill -pid followed by the process ID. Again, this is a bit redundant with Task Manager, but you can use it to kill otherwise unresponsive or hidden programs.
Windows automatically marks your drive for a diagnostic chkdsk scan when symptoms indicate that a local drive has bad sectors, lost clusters, or other logical or physical errors.
If you suspect your hard drive is failing, you can manually initiate a scan. The most basic command is chkdsk c:, which will immediately scan the C: drive, without a need to restart the computer. If you add parameters like /f, /r, /x, or /b, such as in chkdsk /f /r /x /b c:, chkdsk will also fix errors, recover data, dismount the drive, or clear the list of bad sectors, respectively. These actions require a reboot, as they can only run with Windows powered down.
If you see chkdsk run at startup, let it do its thing. If it gets stuck, however, refer to our chkdsk troubleshooting article.
Schtasks is your command prompt access to the Task Scheduler, one of many underrated Windows administrative tools. While you can use the GUI to manage your scheduled tasks, the command prompt lets you copy&paste complex commands to set up multiple similar tasks without having to click through various options. Ultimately, it's much easier to use, once you've committed key parameters to memory.
For example, you could schedule your computer to reboot at 11pm every Friday:
To complement your weekly reboot, you could schedule tasks to launch specific programs on startup:
To duplicate the above command for different programs, just copy, paste, and modify it as needed.
When you need to format a drive, you can either use the Windows File Explorer GUI or you can turn to the command prompt. You'll need Administrator rights to use this command. Be sure you specify the volume you want to format, followed by the desired parameters.
The command below will quick-format the D drive with the exFAT file system, with an allocation unit size of 2048 bytes, and rename the volume to "label" (without the quotes).
You can also use this command to dismount a volume (/X) or, if it's formatted with NTFS, make file compression the default setting (/R). If you're stuck, use format /? to summon help.
Would you like to customize your command prompt to include instructions or certain information? With the prompt command, you can!
Try this one:
You can add the current time, date, drive and path, Windows version number, and so much more.
Type "prompt" to reset your command prompt to default settings or just restart the command prompt. Unfortunately, these settings aren't permanent.
Cluttered up your command prompt window trying out all the commands above? There's one last command you need to know to clean it all up again.
That's all. Bet Marie Kondo didn't know that one.
Windows 8 Only: Recovery Image
Virtually all Windows 8/8.1 computers ship from the factory with a recovery image, but the image may include bloatware you'd rather not have re-installed. Once you've uninstalled the software you can create a new image using the recimg command. Entering this command presents a very detailed explanation of how to use it.
You must have administrator privileges to use the recimg command, and you can only access the custom recovery image you create via the Windows 8 refresh feature.
In Windows 10, system recovery has changed. Windows 10 systems don't come with a recovery partition, which makes it more important than ever to back up your data.
Command and Conquer Your Windows PC
This article can only give you a taste of what's hidden within the Windows command line. When including all variables, there are literally hundreds of commands. Download Microsoft's command line reference guide (in Edge or Internet Explorer) for advanced support and troubleshooting.
The way you type commands might change with the launch of the Windows Terminal. Let's explore some of its attractive features.
Read NextAbout The Author
While completing a PhD, Tina started writing about consumer technology in 2006 and never stopped. Now also an editor and SEO, you can find her on Twitter or hiking a nearby trail.
Subscribe to our newsletter
Join our newsletter for tech tips, reviews, free ebooks, and exclusive deals!
Click here to subscribe
- Science party printables free
- P420i cache module battery
- Honda accord 1994
- Okeechobee county shed permit
Type of computer interface based on entering text commands and viewing text output
A command-line interface (CLI) processes commands to a computer program in the form of lines of text. The program which handles the interface is called a command-line interpreter or command-line processor. Operating systems implement a command-line interface in a shell for interactive access to operating system functions or services. Such access was primarily provided to users by computer terminals starting in the mid-1960s, and continued to be used throughout the 1970s and 1980s on VAX/VMS, Unix systems and personal computer systems including DOS, CP/M and Apple DOS.
Today, many users rely upon graphical user interfaces and menu-driven interactions. However, some programming and maintenance tasks may not have a graphical user interface and may still use a command line.
Alternatives to the command line interface include text-based user interfacemenus (for example, IBM AIX SMIT), keyboard shortcuts, and various desktop metaphors centered on the pointer (usually controlled with a mouse). Examples of this include the Microsoft Windows, DOS Shell, and Mouse Systems PowerPanel. Command-line interfaces are often implemented in terminal devices that are also capable of screen-oriented text-based user interfaces that use cursor addressing to place symbols on a display screen.
Programs with command-line interfaces are generally easier to automate via scripting.
Many software systems implement command-line interfaces for control and operation. This includes programming environments and utility programs.
Comparison to graphical user interfaces
Compared with a graphical user interface, a command-line interface requires fewer system resources to implement. Since options to commands are given in a few characters in each command line, an experienced user may often find the options easier to access. Automation of repetitive tasks is simplified by line editing and history mechanisms for storing frequently used sequences; this may extend to a scripting language that can take parameters and variable options. A command-line history can be kept, allowing review or repetition of commands.
A command-line system may require paper or online manuals for the user's reference, although often a "help" option provides a concise review of the options of a command. The command-line environment may not provide graphical enhancements such as different fonts or extended edit windows found in a GUI. It may be difficult for a new user to become familiar with all the commands and options available, compared with the icons and drop-down menus of a graphical user interface, without repeated reference to manuals.
Operating system command-line interfaces
Operating system (OS) command-line interfaces are usually distinct programs supplied with the operating system. A program that implements such a text interface is often called a command-line interpreter, command processor or shell.
Examples of command-line interpreters include DEC'sDIGITAL Command Language (DCL) in OpenVMS and RSX-11, the various Unix shells (sh, ksh, csh, tcsh, zsh, Bash, etc.), CP/M's CCP, DOS' COMMAND.COM, as well as the OS/2 and the Windows CMD.EXE programs, the latter groups being based heavily on DEC's RSX-11 and RSTS CLIs. Under most operating systems, it is possible to replace the default shell program with alternatives; examples include 4DOS for DOS, 4OS2 for OS/2, and 4NT / Take Command for Windows.
Although the term 'shell' is often used to describe a command-line interpreter, strictly speaking, a 'shell' can be any program that constitutes the user-interface, including fully graphically oriented ones. For example, the default Windows GUI is a shell program named EXPLORER.EXE, as defined in the SHELL=EXPLORER.EXE line in the WIN.INI configuration file. These programs are shells, but not CLIs.
Application command-line interfaces
Application programs (as opposed to operating systems) may also have command-line interfaces.
An application program may support none, any, or all of these three major types of command-line interface mechanisms:
- Parameters: Most operating systems support a means to pass additional information to a program when it is launched. When a program is launched from an OS command-line shell, additional text provided along with the program name is passed to the launched program.
- Interactive command-line sessions: After launch, a program may provide an operator with an independent means to enter commands in the form of text.
- Inter-process communication: Most operating systems support means of inter-process communication (for example, standard streams or named pipes). Command lines from client processes may be redirected to a CLI program by one of these methods.
Some applications support only a CLI, presenting a CLI prompt to the user and acting upon command lines as they are entered. Other programs support both a CLI and a GUI. In some cases, a GUI is simply a wrapper around a separate CLI executable file. In other cases, a program may provide a CLI as an optional alternative to its GUI. CLIs and GUIs often support different functionality. For example, all features of MATLAB, a numerical analysis computer program, are available via the CLI, whereas the MATLAB GUI exposes only a subset of features.
The early Sierra games, such as the first three King's Quest games (1984–1986), used commands from an internal command line to move the character around in the graphic window.
The command-line interface evolved from a form of dialog once conducted by humans over teleprinter (TTY) machines, in which human operators remotely exchanged information, usually one line of text at a time. Early computer systems often used teleprinter machines as the means of interaction with a human operator. The computer became one end of the human-to-human teleprinter model. So instead of a human communicating with another human over a teleprinter, a human communicated with a computer.
The mechanical teleprinter was replaced by a "glass tty", a keyboard and screen emulating the teleprinter. "Smart" terminals permitted additional functions, such as cursor movement over the entire screen, or local editing of data on the terminal for transmission to the computer. As the microcomputer revolution replaced the traditional – minicomputer + terminals – time sharing architecture, hardware terminals were replaced by terminal emulators — PC software that interpreted terminal signals sent through the PC's serial ports. These were typically used to interface an organization's new PC's with their existing mini- or mainframe computers, or to connect PC to PC. Some of these PCs were running Bulletin Board System software.
Early operating system CLIs were implemented as part of resident monitor programs, and could not easily be replaced. The first implementation of the shell as a replaceable component was part of the Multicstime-sharingoperating system. In 1964, MIT Computation Center staff member Louis Pouzin developed the RUNCOM tool for executing command scripts while allowing argument substitution. Pouzin coined the term "shell" to describe the technique of using commands like a programming language, and wrote a paper about how to implement the idea in the Multics operating system. Pouzin returned to his native France in 1965, and the first Multics shell was developed by Glenda Schroeder.
The first Unix shell, the V6 shell, was developed by Ken Thompson in 1971 at Bell Labs and was modeled after Schroeder's Multics shell. The Bourne shell was introduced in 1977 as a replacement for the V6 shell. Although it is used as an interactive command interpreter, it was also intended as a scripting language and contains most of the features that are commonly considered to produce structured programs. The Bourne shell led to the development of the KornShell (ksh), Almquist shell (ash), and the popular Bourne-again shell (or Bash).
Early microcomputers themselves were based on a command-line interface such as CP/M, DOS or AppleSoft BASIC. During the 1980s and 1990s, the introduction of the Apple Macintosh and of Microsoft Windows on PCs saw the command line interface as the primary user interface replaced by the Graphical User Interface. The command line remained available as an alternative user interface, often used by system administrators and other advanced users for system administration, computer programming and batch processing.
In November 2006, Microsoft released version 1.0 of Windows PowerShell (formerly codenamed Monad), which combined features of traditional Unix shells with their proprietary object-oriented .NET Framework. MinGW and Cygwin are open-source packages for Windows that offer a Unix-like CLI. Microsoft provides MKS Inc.'s ksh implementation MKS Korn shell for Windows through their Services for UNIX add-on.
Since 2001, the Macintosh operating system macOS has been based on a Unix-like operating system called Darwin. On these computers, users can access a Unix-like command-line interface by running the terminal emulator program called Terminal, which is found in the Utilities sub-folder of the Applications folder, or by remotely logging into the machine using ssh. Z shell is the default shell for macOS; Bash, tcsh, and the KornShell are also provided. Before macOS Catalina, Bash was the default.
A CLI is used whenever a large vocabulary of commands or queries, coupled with a wide (or arbitrary) range of options, can be entered more rapidly as text than with a pure GUI. This is typically the case with operating system command shells. CLIs are also used by systems with insufficient resources to support a graphical user interface. Some computer language systems (such as Python, Forth, LISP, Rexx, and many dialects of BASIC) provide an interactive command-line mode to allow for rapid evaluation of code.
CLIs are often used by programmers and system administrators, in engineering and scientific environments, and by technically advanced personal computer users. CLIs are also popular among people with visual disabilities since the commands and responses can be displayed using refreshable Braille displays.
Anatomy of a shell CLI
The general pattern of an OS command line interface is:Prompt command param1 param2 param3 … paramN
- Prompt — generated by the program to provide context for the client.
- Command — provided by the client. Commands are usually one of three classes:
- Internal commands are recognized and processed by the command line interpreter itself and not dependent upon any external executable file.
- Included commands run separate executable files generally considered part of the operating environment and always included with the OS.
- External commands run executable files that are not part of the basic OS, but added by other parties for specific purposes and applications.
- param1 …paramN — Optional parameters provided by the client. The format and meaning of the parameters depends upon the command issued. In the case of Included or External commands, the values of the parameters are delivered to the program (specified by the Command) as it is launched by the OS. Parameters may be either Arguments or Options.
In this example, the delimiters between command-line elements are whitespace characters and the end-of-line delimiter is the newline delimiter. This is a widely used (but not universal) convention for command-line interfaces.
A CLI can generally be considered as consisting of syntax and semantics. The syntax is the grammar that all commands must follow. In the case of operating systems, DOS and Unix each define their own set of rules that all commands must follow. In the case of embedded systems, each vendor, such as Nortel, Juniper Networks or Cisco Systems, defines their own proprietary set of rules that all commands within their CLI conform to. These rules also dictate how a user navigates through the system of commands. The semantics define what sort of operations are possible, on what sort of data these operations can be performed, and how the grammar represents these operations and data—the symbolic meaning in the syntax.
Two different CLIs may agree on either syntax or semantics, but it is only when they agree on both that they can be considered sufficiently similar to allow users to use both CLIs without needing to learn anything, as well as to enable re-use of scripts.
A simple CLI will display a prompt, accept a "command line" typed by the user terminated by the Enter key, then execute the specified command and provide textual display of results or error messages. Advanced CLIs will validate, interpret and parameter-expand the command line before executing the specified command, and optionally capture or redirect its output.
Unlike a button or menu item in a GUI, a command line is typically self-documenting, stating exactly what the user wants done. In addition, command lines usually include many defaults that can be changed to customize the results. Useful command lines can be saved by assigning a character string or alias to represent the full command, or several commands can be grouped to perform a more complex sequence – for instance, compile the program, install it, and run it — creating a single entity, called a command procedure or script which itself can be treated as a command. These advantages mean that a user must figure out a complex command or series of commands only once, because they can be saved, to be used again.
The commands given to a CLI shell are often in one of the following forms:
where doSomething is, in effect, a verb, how an adverb (for example, should the command be executed "verbosely" or "quietly") and toFiles an object or objects (typically one or more files) on which the command should act. The in the third example is a redirection operator, telling the command-line interpreter to send the output of the command not to its own standard output (the screen) but to the named file. This will overwrite the file. Using will redirect the output and append it to the file. Another redirection operator is the vertical bar (), which creates a pipeline where the output of one command becomes the input to the next command.
CLI and resource protection
One can modify the set of available commands by modifying which paths appear in the PATH environment variable. Under Unix, commands also need be marked as executable files. The directories in the path variable are searched in the order they are given. By re-ordering the path, one can run e.g. \OS2\MDOS\E.EXE instead of \OS2\E.EXE, when the default is the opposite. Renaming of the executables also works: people often rename their favourite editor to EDIT, for example.
The command line allows one to restrict available commands, such as access to advanced internal commands. The Windows CMD.EXE does this. Often, shareware programs will limit the range of commands, including printing a command 'your administrator has disabled running batch files' from the prompt.[clarification needed]
Some CLIs, such as those in network routers, have a hierarchy of modes, with a different set of commands supported in each mode. The set of commands are grouped by association with security, system, interface, etc. In these systems the user might traverse through a series of sub-modes. For example, if the CLI had two modes called interface and system, the user might use the command interface to enter the interface mode. At this point, commands from the system mode may not be accessible until the user exits the interface mode and enters the system mode.
"Command prompt" redirects here. For the Windows component named Command Prompt, see cmd.exe.
A command prompt (or just prompt) is a sequence of (one or more) characters used in a command-line interface to indicate readiness to accept commands. It literally prompts the user to take action. A prompt usually ends with one of the characters , , ,, or  and often includes other information, such as the path of the current working directory and the hostname.
On many Unix and derivative systems, the prompt commonly ends in or if the user is a normal user, but in if the user is a superuser ("root" in Unix terminology).
End-users can often modify prompts. Depending on the environment, they may include colors, special characters, and other elements (like variables and functions for the current time, user, shell number or working directory) in order, for instance, to make the prompt more informative or visually pleasing, to distinguish sessions on various machines, or to indicate the current level of nesting of commands. On some systems, special tokens in the definition of the prompt can be used to cause external programs to be called by the command-line interpreter while displaying the prompt.
In DOS' COMMAND.COM and in Windows NT's cmd.exe users can modify the prompt by issuing a command or by directly changing the value of the corresponding environment variable. The default of most modern systems, the style is obtained, for instance, with . The default of older DOS systems, is obtained by just , although on some systems this produces the newer style, unless used on floppy drives A: or B:; on those systems can be used to override the automatic default and explicitly switch to the older style.
Many Unix systems feature the variable (Prompt String 1), although other variables also may affect the prompt (depending on the shell used). In the Bash shell, a prompt of the form:
could be set by issuing the command
In zsh the variable controls an optional "prompt" on the right-hand side of the display. It is not a real prompt in that the location of text entry does not change. It is used to display information on the same line as the prompt, but right-justified.
In RISC OS the command prompt is a symbol, and thus (OS) CLI commands are often referred to as "star commands". One can also access the same commands from other command lines (such as the BBC BASIC command line), by preceding the command with a .
A command-line argument or parameter is an item of information provided to a program when it is started. A program can have many command-line arguments that identify sources or destinations of information, or that alter the operation of the program.
When a command processor is active a program is typically invoked by typing its name followed by command-line arguments (if any). For example, in Unix and Unix-like environments, an example of a command-line argument is:
"file.s" is a command-line argument which tells the program rm to remove the file "file.s".
Some programming languages, such as C, C++ and Java, allow a program to interpret the command-line arguments by handling them as string parameters in the main function. Other languages, such as Python, expose operating system specific API (functionality) through module, and in particular for "command-line arguments".
In Unix-like operating systems, a single hyphen used in place of a file name is a special value specifying that a program should handle data coming from the standard input or send data to the standard output.
A command-line option or simply option (also known as a flag or switch) modifies the operation of a command; the effect is determined by the command's program. Options follow the command name on the command line, separated by spaces. A space before the first option is not always required, such as and in DOS, which have the same effect of listing the DIR command's available options, whereas (in many versions of Unix) does require the option to be preceded by at least one space (and is case-sensitive).
The format of options varies widely between operating systems. In most cases the syntax is by convention rather than an operating system requirement; the entire command line is simply a string passed to a program, which can process it in any way the programmer wants, so long as the interpreter can tell where the command name ends and its arguments and options begin.
A few representative samples of command-line options, all relating to listing files in a directory, to illustrate some conventions:
|Operating system||Command||Valid alternative||Notes|
|OpenVMS||instruct the directory command to also display the ownership of the files.|
Note the Directory command name is not case sensitive, and can be abbreviated to as few letters as required to remain unique.
|Windows||display ownership of files whose names begin with "D", sorted by size, smallest first.|
Note spaces around argument d* are required.
|Unix-like systems||display in long format files and directories beginning with "D" (but not "d"), sorted by size (largest first).|
Note spaces are required around all arguments and options, but some can be run together, e.g. -lS is the same as -l -S.
|Data General RDOSCLI||list every attribute for files created before 26 April 1980.|
Note the /B at the end of the date argument is a local switch, that modifies the meaning of that argument, while /S and /E are global switches, i.e. apply to the whole command.
See also: Tab completion
In Multics, command-line options and subsystem keywords may be abbreviated. This idea appears to derive from the PL/I programming language, with its shortened keywords (e.g., STRG for STRINGRANGE and DCL for DECLARE). For example, in the Multics "forum" subsystem, the -long_subject parameter can be abbreviated -lgsj. It is also common for Multics commands to be abbreviated, typically corresponding to the initial letters of the words that are strung together with underscores to form command names, such as the use of did for delete_iacl_dir.
In some other systems abbreviations are automatic, such as permitting enough of the first characters of a command name to uniquely identify it (such as as an abbreviation for ) while others may have some specific abbreviations pre-programmed (e.g. for in COMMAND.COM) or user-defined via batch scripts and aliases (e.g. in tcsh).
Option conventions in DOS, Windows, OS/2
On DOS, OS/2 and Windows, different programs called from their COMMAND.COM or CMD.EXE (or internal their commands) may use different syntax within the same operating system. For example:
- Options may be indicated by either of the "switch characters": , , or either may be allowed. See below.
- They may or may not be case-sensitive.
- Sometimes options and their arguments are run together, sometimes separated by whitespace, and sometimes by a character, typically or ; thus , , , .
- Some programs allow single-character options to be combined; others do not. The switch may mean the same as , or it may be incorrect, or it may even be a valid but different parameter.
In DOS, OS/2 and Windows, the forward slash () is most prevalent, although the hyphen-minus is also sometimes used. In many versions of DOS (MS-DOS/PC DOS 2.xx and higher, all versions of DR-DOS since 5.0, as well as PTS-DOS, Embedded DOS, FreeDOS and RxDOS) the switch character (sometimes abbreviated switchar or switchchar) to be used is defined by a value returned from a system call (INT 21h/AX=3700h). The default character returned by this API is , but can be changed to a hyphen-minus on the above-mentioned systems, except for under Datalight ROM-DOS and MS-DOS/PC DOS 5.0 and higher, which always return from this call (unless one of many available TSRs to reenable the SwitChar feature is loaded). In some of these systems (MS-DOS/PC DOS 2.xx, DOS Plus 2.1, DR-DOS 7.02 and higher, PTS-DOS, Embedded DOS, FreeDOS and RxDOS), the setting can also be pre-configured by a SWITCHAR directive in CONFIG.SYS. General Software's Embedded DOS provides a SWITCH command for the same purpose, whereas 4DOS allows the setting to be changed via . Under DR-DOS, if the setting has been changed from , the first directory separator in the display of the PROMPT parameter will change to a forward slash (which is also a valid directory separator in DOS, FlexOS, 4680 OS, 4690 OS, OS/2 and Windows) thereby serving as a visual clue to indicate the change. Also, the current setting is reflected also in the built-in help screens. Some versions of DR-DOS COMMAND.COM also support a PROMPT token to display the current setting. COMMAND.COM since DR-DOS 7.02 also provides a pseudo-environment variable named to allow portable batchjobs to be written. Several external DR-DOS commands additionally support an environment variable to override the system setting.
However, many programs are hardwired to use only, rather than retrieving the switch setting before parsing command-line arguments. A very small number, mainly ports from Unix-like systems, are programmed to accept "-" even if the switch character is not set to it (for example and , supplied with Microsoft Windows, will accept the /? option to list available options, and yet the list will specify the "-" convention).
Option conventions in Unix-like systems
In Unix-like systems, the ASCII hyphen-minus begins options; the new (and GNU) convention is to use two hyphens then a word (e.g. ) to identify the option's use while the old convention (and still available as an option for frequently-used options) is to use one hyphen then one letter (e.g., ); if one hyphen is followed by two or more letters it may mean two options are being specified, or it may mean the second and subsequent letters are a parameter (such as filename or date) for the first option.
Two hyphen-minus characters without following letters () may indicate that the remaining arguments should not be treated as options, which is useful for example if a file name itself begins with a hyphen, or if further arguments are meant for an inner command (e.g., sudo). Double hyphen-minuses are also sometimes used to prefix "long options" where more descriptive option names are used. This is a common feature of GNU software. The getopt function and program, and the getopts command are usually used for parsing command-line options.
Unix command names, arguments and options are case-sensitive (except in a few examples, mainly where popular commands from other operating systems have been ported to Unix).
Option conventions in other systems
FlexOS, 4680 OS and 4690 OS use .
CP/M typically used .
Conversational Monitor System (CMS) uses a single left parenthesis to separate options at the end of the command from the other arguments. For example, in the following command the options indicate that the target file should be replaced if it exists, and the date and time of the source file should be retained on the copy:
Data General's CLI under their RDOS, AOS, etc. operating systems, as well as the version of CLI that came with their Business Basic, uses only as the switch character, is case-insensitive, and allows "local switches" on some arguments to control the way they are interpreted, such as has the global option "U" to the macro assembler command to append user symbols, but two local switches, one to specify LIB should be skipped on pass 2 and the other to direct listing to the printer, $LPT.
Built-in usage help
See also: help (command)
One of the criticisms of a CLI is the lack of cues to the user as to the available actions. In contrast, GUIs usually inform the user of available actions with menus, icons, or other visual cues. To overcome this limitation, many CLI programs display a brief summary of its valid parameters, typically when invoked with no arguments or one of , , , , , , , , , or .
However, entering a program name without parameters in the hope that it will display usage help can be hazardous, as programs and scripts for which command line arguments are optional will execute without further notice.
Although desirable at least for the help parameter, programs may not support all option lead-in characters exemplified above. Under DOS, where the default command-line option character can be changed from to , programs may query the SwitChar API in order to determine the current setting. So, if a program is not hardwired to support them all, a user may need to know the current setting even to be able to reliably request help. If the SwitChar has been changed to and therefore the character is accepted as alternative path delimiter also at the DOS command line, programs may misinterpret options like or as paths rather than help parameters. However, if given as first or only parameter, most DOS programs will, by convention, accept it as request for help regardless of the current SwitChar setting.
In some cases, different levels of help can be selected for a program. Some programs supporting this allow to give a verbosity level as an optional argument to the help parameter (as in , , etc.) or they give just a short help on help parameters with question mark and a longer help screen for the other help options.
Depending on the program, additional or more specific help on accepted parameters is sometimes available by either providing the parameter in question as an argument to the help parameter or vice versa (as in or in (assuming would be another parameter supported by the program)).[nb 1]
In a similar fashion to the help parameter, but much less common, some programs provide additional information about themselves (like mode, status, version, author, license or contact information) when invoked with an "about" parameter like , , , or .
Since the and characters typically also serve other purposes at the command line, they may not be available in all scenarios, therefore, they should not be the only options to access the corresponding help information.
If more detailed help is necessary than provided by a program's built-in internal help, many systems support a dedicated external "" command (or similar), which accepts a command name as calling parameter and will invoke an external help system.
In the DR-DOS family, typing or at the COMMAND.COM prompt instead of a command itself will display a dynamically generated list of available internal commands;4DOS and NDOS support the same feature by typing at the prompt (which is also accepted by newer versions of DR-DOS COMMAND.COM); internal commands can be individually disabled or reenabled via . In addition to this, some newer versions of DR-DOS COMMAND.COM also accept a command to display a list of available built-in pseudo-environment variables. Besides their purpose as quick help reference this can be used in batchjobs to query the facilities of the underlying command-line processor.
Command description syntax
Built-in usage help and man pages commonly employ a small syntax to describe the valid command form:[nb 2]
- angle brackets for required parameters:
- square brackets for optional parameters:
- ellipses for repeated items:
- vertical bars for choice of items:
Notice that these characters have different meanings than when used directly in the shell. Angle brackets may be omitted when confusing the parameter name with a literal string is not likely.
The space character
In many areas of computing, but particularly in the command line, the space character can cause problems as it has two distinct and incompatible functions: as part of a command or parameter, or as a parameter or name separator. Ambiguity can be prevented either by prohibiting embedded spaces in file and directory names in the first place (for example, by substituting them with underscores), or by enclosing a name with embedded spaces between quote characters or using an escape character before the space, usually a backslash (). For example
is ambiguous (is "program name" part of the program name, or two parameters?); however
are not ambiguous. Unix-based operating systems minimize the use of embedded spaces to minimize the need for quotes. In Microsoft Windows, one often has to use quotes because embedded spaces (such as in directory names) are common.
Although most users think of the shell as an interactive command interpreter, it is really a programming language in which each statement runs a command. Because it must satisfy both the interactive and programming aspects of command execution, it is a strange language, shaped as much by history as by design.
— Brian W. Kernighan & Rob Pike
See also: List of command-line interpreters
The term command-line interpreter (CLI) is applied to computer programs designed to interpret a sequence of lines of text which may be entered by a user, read from a file or another kind of data stream. The context of interpretation is usually one of a given operating system or programming language.
Command-line interpreters allow users to issue various commands in a very efficient (and often terse) way. This requires the user to know the names of the commands and their parameters, and the syntax of the language that is interpreted.
The Unix mechanism and OS/2 EXTPROC command facilitate the passing of batch files to external processors. One can use these mechanisms to write specific command processors for dedicated uses, and process external data files which reside in batch files.
Many graphical interfaces, such as the OS/2 Presentation Manager and early versions of Microsoft Windows use command-lines to call helper programs to open documents and programs. The commands are stored in the graphical shell[clarification needed] or in files like the registry or the OS/2 file.
The earliest computers did not support interactive input/output devices, often relying on sense switches and lights to communicate with the computer operator. This was adequate for batch systems that ran one program at a time, often with the programmer acting as operator. This also had the advantage of low overhead, since lights and switches could be tested and set with one machine instruction. Later a single system console was added to allow the operator to communicate with the system.
From the 1960s onwards, user interaction with computers was primarily by means of command-line interfaces, initially on machines like the Teletype Model 33 ASR, but then on early CRT-based computer terminals such as the VT52.
All of these devices were purely text based, with no ability to display graphic or pictures.[nb 3] For business application programs, text-based menus were used, but for more general interaction the command line was the interface.
Around 1964 Louis Pouzin introduced the concept and the name shell in Multics, building on earlier, simpler facilities in the Compatible Time-Sharing System (CTSS).[better source needed]
From the early 1970s the Unix operating system adapted the concept of a powerful command-line environment, and introduced the ability to pipe the output of one command in as input to another. Unix also had the capability to save and re-run strings of commands as "shell scripts" which acted like custom commands.
The command-line was also the main interface for the early home computers such as the Commodore PET, Apple II and BBC Micro – almost always in the form of a BASIC interpreter. When more powerful business oriented microcomputers arrived with CP/M and later DOS computers such as the IBM PC, the command-line began to borrow some of the syntax and features of the Unix shells such as globbing and piping of output.
The command-line was first seriously challenged by the PARCGUI approach used in the 1983 Apple Lisa and the 1984 Apple Macintosh. A few computer users used GUIs such as GEOS and Windows 3.1 but the majority of IBM PC users did not replace their COMMAND.COM shell with a GUI until Windows 95 was released in 1995.
Modern usage as an operating system shell
While most non-expert computer users now use a GUI almost exclusively, more advanced users have access to powerful command-line environments:
- The default VAX/VMS command shell, using the DCL language, has been ported to Windows systems at least three times, including PC-DCL and Acceler8 DCL Lite. Unix command shells have been ported to VMS and DOS/Windows 95 and Windows NT types of operating systems.
- COMMAND.COM is the command-line interpreter of MS-DOS, IBM PC DOS, and clones such as DR-DOS, SISNE plus, PTS-DOS, ROM-DOS, and FreeDOS.
- Windows Resource Kit and Windows Services for UNIX include Korn and the Bourne shells along with a Perl interpreter (Services for UNIX contains ActiveStateActivePerl in later versions and Interix for versions 1 and 2 and a shell compiled by Microsoft)
- IBM OS/2 (and derivatives such as eComStation and ArcaOS) has the cmd.exe processor. This copies the COMMAND.COM commands, with extensions to REXX.
- cmd.exe is part of the Windows NT stream of operating systems.
- Yet another cmd.exe is a stripped-down shell for Windows CE 3.0.
- An MS-DOS type interpreter called PocketDOS has been ported to Windows CE machines; the most recent release is almost identical to MS-DOS 6.22 and can also run Windows 1, 2, and 3.0, QBasic and other development tools, 4NT and 4DOS. The latest release includes several shells, namely MS-DOS 6.22, PC DOS 7, DR DOS 3.xx, and others.
- Windows users might use the CScript interface to alternate programs, from command-line. PowerShell provides a command-line interface, but its applets are not written in Shell script. Implementations of the Unix shell are also available as part of the POSIX sub-system,Cygwin, MKS Toolkit, UWIN, Hamilton C shell and other software packages. Available shells for these interoperability tools include csh, ksh, sh, Bash, rsh, tclsh and less commonly zsh, psh
- Implementations of PHP have a shell for interactive use called php-cli.
- Standard Tcl/Tk has two interactive shells, Tclsh and Wish, the latter being the GUI version.
- Python, Ruby, Lua, XLNT, and other interpreters also have command shells for interactive use.
- FreeBSD uses tcsh as its default interactive shell for the superuser, and ash as default scripting shell.
- Many Linux distributions have the Bash implementation of the Unix shell.
- Apple macOS and some Linux distributions use zsh. Previously, macOS used tcsh and Bash.
- Embedded Linux (and other embedded Unix-like) devices often use the Ash implementation of the Unix shell, as part of Busybox.
- Android uses the mksh shell, which replaces a shell derived from ash that was used in older Android versions, supplemented with commands from the separate toolbox binary.
- Routers with Cisco IOS,Junos and many others are commonly configured from the command line.
Most command-line interpreters support scripting, to various extents. (They are, after all, interpreters of an interpreted programming language, albeit in many cases the language is unique to the particular command-line interpreter.) They will interpret scripts (variously termed shell scripts or batch files) written in the language that they interpret. Some command-line interpreters also incorporate the interpreter engines of other languages, such as REXX, in addition to their own, allowing the executing of scripts, in those languages, directly within the command-line interpreter itself.
Conversely, scripting programming languages, in particular those with an evalfunction (such as REXX, Perl, Python, Ruby or Jython), can be used to implement command-line interpreters and filters. For a few operating systems, most notably DOS, such a command interpreter provides a more flexible command-line interface than the one supplied. In other cases, such a command interpreter can present a highly customised user interface employing the user interface and input/output facilities of the language.
Other command-line interfaces
The command line provides an interface between programs as well as the user. In this sense, a command line is an alternative to a dialog box. Editors and databases present a command line, in which alternate command processors might run. On the other hand, one might have options on the command line, which opens a dialog box. The latest version of 'Take Command' has this feature. DBase used a dialog box to construct command lines, which could be further edited before use.
Programs like BASIC, diskpart, Edlin, and QBASIC all provide command-line interfaces, some of which use the system shell. Basic is modeled on the default interface for 8-bit Intel computers. Calculators can be run as command-line or dialog interfaces.
Emacs provides a command-line interface in the form of its minibuffer. Commands and arguments can be entered using Emacs standard text editing support, and output is displayed in another buffer.
There are a number of text mode games, like Adventure or King's Quest 1-3, which relied on the user typing commands at the bottom of the screen. One controls the character by typing commands like 'get ring' or 'look'. The program returns a text which describes how the character sees it, or makes the action happen. The text adventureThe Hitchhiker's Guide to the Galaxy, a piece of interactive fiction based on Douglas Adam's book of the same name, is a teletype-style command-line game.
The most notable of these interfaces is the standard streams interface, which allows the output of one command to be passed to the input of another. Text files can serve either purpose as well. This provides the interfaces of piping, filters and redirection. Under Unix, devices are files too, so the normal type of file for the shell used for stdin,stdout and stderr is a tty device file.
Another command-line interface allows a shell program to launch helper programs, either to launch documents or start a program. The command is processed internally by the shell, and then passed on to another program to launch the document. The graphical interface of Windows and OS/2 rely heavily on command-lines passed through to other programs – console or graphical, which then usually process the command line without presenting a user-console.
Programs like the OS/2 E editor and some other IBM editors, can process command-lines normally meant for the shell, the output being placed directly in the document window.
A web browser's URL input field can be used as a command line. It can be used to "launch" web apps, access browser configuration, as well as perform a search. Google, which has been called "the command line of the internet" will perform a domain-specific search when it detects search parameters in a known format. This functionality is present whether the search is triggered from a browser field or on Google's website.
Many video games on the PC feature a command line interface often referred to as a console. It is typically used by the game developers during development and by mod developers for debugging purposes as well as for cheating or skipping parts of the game.
- ^An example is the comprehensive internal help system of the DR-DOS 7.03DEBUG command, which can be invoked via at the debug prompt (rather than only the default overview). Specific help pages can be selected via (where is the number of the page). Additionally, help for specific commands can be displayed by specifying the command name after , f.e. will invoke help for the various dump commands (like etc.). Some of these features were already supported by the DR DOS 3.41SID86 and GEMSID.
- ^Conventions for describing commands on DOS-like operating systems. Notable difference: The Windows Server 2003 R2 documentation uses italic letters for "Information that the user must supply", while the Server 2008 documentation uses angle brackets. Italics can not be displayed by the internal "help" command while there is no problem with angle brackets.
- ^With the exception of ASCII art.
- ^"Unix Shells".
- ^ ab"The Origin of the Shell". www.multicians.org. Retrieved 2017-04-12.
- ^Metz, Cade (2013-01-03). "Say Bonjour to the Internet's Long-Lost French Uncle". Wired. Retrieved 2017-07-31.
- ^Mazières, David (Fall 2004). "MULTICS - The First Seven Years". Advanced Operating Systems. Stanford Computer Science Department. Retrieved 2017-08-01.
- ^ abJones, M. (2011-12-06). "Evolution of shells in Linux". developerWorks. IBM. Retrieved 2017-08-01.
- ^"GNU BASH Reference".
- ^"Microsoft Windows Command Shell Overview".
- ^SID Users Guide(PDF). Digital Research. 1978. 595-2549. Archived(PDF) from the original on 2019-10-20. Retrieved 2020-02-06. (4+69 pages)
- ^SID-86 User's Guide for CP/M-86 (2 ed.). Digital Research. August 1982 [March 1982]. SID86UG.WS4. Archived from the original on 2019-10-20. Retrieved 2020-02-06. (NB. A retyped version of the manual by Emmanuel Roche with Q, SR, and Z commands added.)
- ^ abcdefghijkPaul, Matthias R. (1997-07-30). NWDOS-TIPs – Tips & Tricks rund um Novell DOS 7, mit Blick auf undokumentierte Details, Bugs und Workarounds. MPDOSTIP. Release 157 (in German) (3 ed.). Archived from the original on 2017-09-10. Retrieved 2014-09-06. (NB. NWDOSTIP.TXT is a comprehensive work on Novell DOS 7 and OpenDOS 7.01, including the description of many undocumented features and internals. It is part of the author's yet larger MPDOSTIP.ZIP collection maintained up to 2001 and distributed on many sites at the time. The provided link points to a HTML-converted older version of the NWDOSTIP.TXT file.)
- ^Parker, Steve (2011). "Chapter 11: Choosing and using shells". Shell Scripting: Expert Recipes for Linux, Bash and more. Programmer to programmer. Indianapolis, USA: John Wiley & Sons. p. 262. ISBN .
- ^RISC OS 3 User Guide(PDF). Acorn Computers Limited. 1992-03-01. p. 125.
- ^ abcdBrothers, Hardin; Rawson, Tom; Conn, Rex C.; Paul, Matthias R.; Dye, Charles E.; Georgiev, Luchezar I. (2002-02-27). 4DOS 8.00 online help.
- ^Paul, Matthias R. (1998-01-09). DELTREE.BAT R1.01 Extended file and directory delete. Caldera, Inc. Archived from the original on 2019-04-08. Retrieved 2019-04-08.
- ^DR-DOS 7.03 WHATSNEW.TXT — Changes from DR-DOS 7.02 to DR-DOS 7.03. Caldera, Inc. 1998-12-24. Archived from the original on 2019-04-08. Retrieved 2019-04-08.
- ^"Argument Syntax (The GNU C Library)". www.gnu.org. Retrieved 2021-07-09.
- ^ abcPaul, Matthias R. (2002-05-13). "[fd-dev] mkeyb". freedos-dev. Archived from the original on 2018-09-10. Retrieved 2018-09-10.
- ^ abPaul, Matthias R. (2002-01-09). "SID86". Newsgroup: comp.os.cpm. Retrieved 2018-04-08.
- ^ abPaul, Matthias R.; Frinke, Axel C. (2006-01-16). FreeKEYB - Advanced international DOS keyboard and console driver (User Manual) (v7 preliminary ed.).
- ^CCI Multiuser DOS 7.22 GOLD Online Documentation. Concurrent Controls, Inc. (CCI). 1997-02-10. HELP.HLP. (NB. The symbolic instruction debugger SID86 provides a short help screen on and comprehensive help on .)
- ^Paul, Matthias R. (1997-05-24) . DRDOSTIP.TXT – Tips und Tricks für DR DOS 3.41 - 5.0. MPDOSTIP (in German) (47 ed.). Archived from the original on 2016-11-07. Retrieved 2016-11-07.
- ^"The Open Group Base Specifications Issue 7, Chapter 12.1 Utility Argument Syntax". The Open Group. 2008. Retrieved 2013-04-07. – Linux Conventions and Miscellany Manual (NB. Conventions for describing commands on Unix-like operating systems.)
- ^"Command shell overview". Windows Server 2003 Product Help. Microsoft. 2005-01-21. Retrieved 2013-04-07.
- ^"Command-Line Syntax Key". Windows Server 2008 R2 TechNet Library. Microsoft. 2010-01-25. Retrieved 2013-04-07.
- ^Kernighan, Brian W.; Pike, Rob (1984). The UNIX Programming Environment. Englewood Cliffs: Prentice-Hall. ISBN .
- ^Pouzin, Louis. "The Origin of the Shell". Multicians.org. Retrieved 2013-09-22.
- ^"Remembering Windows 95's launch 15 years later".
- ^"A history of Windows". windows.microsoft.com. Archived from the original on 2015-03-01.
- ^"Windows POSIX shell compatibility".
- ^"master - platform/external/mksh - Git at Google". android.googlesource.com. Retrieved 2018-03-18.
- ^"Android adb shell - ash or ksh?". stackoverflow.com. Retrieved 2018-03-14.
- ^"Android sh source". Archived from the original on 2012-12-17.
- ^"Android toolbox source".
- ^"Cisco IOS Configuration Fundamentals Configuration Guide, Release 12.2". Cisco. 2013-10-30. Using the Command-Line Interface.
- ^"Command-Line Interface Overview". www.juniper.net. Retrieved 2018-03-14.
- ^"Google strange goodness".
- ^jQuery Terminal Emulator
- ^DuckDuckGo TTY
Commands command line
All supported versions of Windows (server and client) have a set of Win32 console commands built in.
This set of documentation describes the Windows Commands you can use to automate tasks by using scripts or scripting tools.
The information that is contained in this topic applies to:
- Windows Server 2019
- Windows Server (Semi-Annual Channel)
- Windows Server 2016
- Windows Server 2012 R2
- Windows Server 2012
- Windows Server 2008 R2
- Windows Server 2008
- Windows 10
- Windows 8.1
Command shell overview
The Command shell was the first shell built into Windows to automate routine tasks, like user account management or nightly backups, with batch (.bat) files. With Windows Script Host you could run more sophisticated scripts in the Command shell. For more information, see cscript or wscript. You can perform operations more efficiently by using scripts than you can by using the user interface. Scripts accept all Commands that are available at the command line.
Windows has two command shells: The Command shell and PowerShell. Each shell is a software program that provides direct communication between you and the operating system or application, providing an environment to automate IT operations.
PowerShell was designed to extend the capabilities of the Command shell to run PowerShell commands called cmdlets. Cmdlets are similar to Windows Commands but provide a more extensible scripting language. You can run Windows Commands and PowerShell cmdlets in Powershell, but the Command shell can only run Windows Commands and not PowerShell cmdlets.
For the most robust, up-to-date Windows automation, we recommend using PowerShell instead of Windows Commands or Windows Script Host for Windows automation.
You can also download and install PowerShell Core, the open source version of PowerShell.
Incorrectly editing the registry may severely damage your system. Before making the following changes to the registry, you should back up any valued data on the computer.
To enable or disable file and directory name completion in the Command shell on a computer or user logon session, run regedit.exe and set the following reg_DWOrd value:
To set the reg_DWOrd value, use the hexadecimal value of a control character for a particular function (for example, 0 9 is Tab and 0 08 is Backspace). User-specified settings take precedence over computer settings, and command-line options take precedence over registry settings.
Command-line reference A-Z
To find information about a specific command, in the following A-Z menu, click the letter that the command starts with, and then click the command name.
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
The Windows command prompt is a feature that’s been a core part of the Windows operating system for a long time. There are some CMD commands that are so useful and easy to use that even regular users see the Windows command prompt as a key part of the operating system.
There are always rumors that it will be phased out at some point, but that’s unlikely to happen any time soon.
The following are 21 of the best CMD commands you should know if you want to have more control over your Windows PC.
Also, be sure to check out our YouTube video where we go over the commands listed in this article:
1. ASSOC: Fix File Associations
One of the most powerful tools in the CMD command library is the ASSOC command.
Your computer associates certain file extensions with certain programs. This is how your computer knows to open Adobe when you double click a PDF file, or Microsoft Word when you double click a DOC file.
You can view all the file associations your computer knows about by typing ASSOC in the command window. You’ll see the file extension and the program it’s associated with.
You can set the association by typing something like assoc .doc=Word.Document.8.
2. FC: File Compare
Sometimes when files are changed over time, it’s hard to remember what the differences were between versions. You may not know that a CMD command offers the ability to compare files and see all differences, but it’s true.
The FC command performs either an ascii or a binary file comparison and will list all of the differences that it finds.
Fc /a File1.txt File2.txt will compare two ascii files.
Fc /b Picture1.jpg Picture2.jpg will do a binary compare on two images.
3. IPCONFIG: IP Configuration
Network troubleshooting is never simple, but one command that makes it much easier is IPCONFIG.
Using this command in the CMD command prompt returns detailed information about your current network adapter connection including:
- Current IP Address
- Subnet Mask
- Default Gateway IP
- Current domain
This information can help you troubleshoot router issues and other connection issues you could be having with your network adapter.
4. NETSTAT: Network Statistics
Concerned that you could have malware running on your computer that’s connecting to internet locations without you knowing about it?
If you run a NETSTAT command in the command prompt, you can get a list of all active TCP connections from your computer.
5. PING: Send Test Packets
An IT Analyst’s best friend is the PING command. Running this command sends test packets over the network to the target system.
You can use the PING command to test whether your computer can access another computer, a server, or even a website. It can help with revealing network disconnections. It also provides transit time for the packets in milliseconds, so it also reveals a bad network connection as well.
6. TRACERT: Trace Route
TRACERT is a fascinating Windows Command to use. If you’re ever curious to see the path your internet traffic takes to get from your browser to a remote system like Google servers, you can use TRACERT to see it.
The command stands for “Trace Route”, which sends packets out to a remote destination (server or website), and provides you with all of the following information:
- Number of hops (intermediate servers) before getting to the destination
- Time it takes to get to each hop
- The IP and sometimes the name of each hop
TRACERT can reveal how the routes of your internet requests change depending where you’re accessing the web. It also helps with troubleshooting a router or switch on a local network that may be problematic.
7. POWERCFG: Power Configuration
Are you frustrated with how quickly your laptop seems to run out of power? It could be that your power settings are configured as efficiently as possible. There’s a windows CMD command called POWERCFG (power configuration) that can help. Run the command prompt as an administrator and type powercfg – energy to get a full power efficiency report.
The process can take up to about a minute, but when it’s done, you’ll see whether there are any warnings or errors that might help you improve the power efficiency of your system.
View the energy-report.html file to see the details of those errors and warnings.
8. SHUTDOWN: Turn Off Computer
The SHUTDOWN command is a pretty versatile command that lets you shutdown the computer but control the behavior of that shutdown. It’s commonly used as a scheduled task or part of an IT batch job after patches have been applied to a computer system.
Typing shutdown /i from the command prompt will initiate a shutdown, but it’ll upon a GUI to give the user an option on whether to restart or do a full shutdown. If you don’t want to have any GUI pop up, you can just issue a shutdown /s command.
There is a long list of other parameters you can use to do a log off, hibernate, restart, and more. Just type shutdown without any arguments to see them all.
9. SYSTEMINFO: System Information
If you need to know what brand of network card you have, processor details, or the exact version of your Windows OS, the SYSTEMINFO command can help.
This command polls your system and pulls the most important information about your system. It lists the information in a clean format that’s easy to read.
10. SFC: System File Checker
If you’re ever concerned that a virus or some other software might have corrupted your core system files, there’s a Windows command that can scan those files and ensure their integrity.
You need to launch CMD as administrator (right click and choose Run as Administrator). Typing SFC /SCANNOW will check the integrity of all protected system files. If a problem is found, the files will be repaired with backed-up system files.
The SFC command also lets you:
- /VERIFYONLY: Check the integrity but don’t repair the files.
- /SCANFILE: Scan the integrity of specific files and fix if corrupted.
- /VERIFYFILE: Verify the integrity of specific files but don’t repair them.
- /OFFBOOTDIR: Use this to do repairs on an offline boot directory.
- /OFFWINDIR: Use this to do repairs on an offline Windows directory.
- /OFFLOGFILE: Specify a path to save a log file with scan results.
The scan can take up to 10 or 15 minutes, so give it time.
11. NET USE: Map drives
If you want to map a new drive, you could always open File Explorer, right click on This PC, and go through the Map Network Drive wizard. However, using the NET USE command, you can do the same thing with one command string.
For example, if you have a share folder on a computer on your network called \\OTHER-COMPUTER\SHARE\, you can map this as your own Z: drive by typing the command:
Net use Z: “\\OTHER-COMPUTER\SHARE” /persistent:yes
The persistent switch tells your computer that you want this drive remapped every time you log back into your computer.
12. CHKDSK: Check Disk
While the SFC command only checks the integrity of core system files, you can use the CHKDSK command to scan an entire drive.
The command to check the C: drive and repair any problems, launch the command window as an administrator and type CHKDSK /f C:.
This command checks for things like:
- File fragmentation
- Disk errors
- Bad sectors
The command can fix any disk errors (if possible). When the command is finished, you’ll see a status of the scan and what actions were taken.
13. SCHTASKS: Schedule Tasks
Windows comes with a wizard for creating scheduled tasks. For example, maybe you have a BAT file stored on C:\temp that you want to run every day at noon.
You’d have to click through the Scheduled Task wizard to configure this. Or you can type a single SCHTASKS command to set it up.
SCHTASKS /Create /SC HOURLY /MO 12 /TR Example /TN c:\temp\File1.bat
The scheduled switch accepts arguments like minute, hourly, daily, and monthly. Then you specify the frequency with the /MO command.
If you typed the command correctly, you’ll see the response, SUCCESS: The scheduled task “Example” has successfully been created.
14. ATTRIB: Change File Attributes
In Windows, you can change file attributes by right clicking on a file and finding the right property to change. However, instead of hunting around for the file attribute, you can use the ATTRIB command to set the file attributes.
For example, if you type: ATTRIB +R +H C:\temp\File1.bat, it’ll set File1.bat as a hidden, read-only file.
There is no response when it’s successful, so unless you see an error message, the command worked.
Other Windows CMD Commands
As you can see, there are some powerful and useful things you can do with the Windows command prompt, if you know the right commands.
Believe it or not, there are even more commands that will give you the ability to do some things you probably never realized just by typing a simple command.
- BITSADMIN: Initiate upload or download jobs over the network or internet and monitor the current state of those file transfers.
- COLOR: Change the background color of the command prompt window.
- COMP: Compare the contents of any two files to see the differences.
- FIND/FINDSTR: Search for strings inside of any ASCII files.
- PROMPT: Change the command prompt from C:\> to something else.
- TITLE: Change the title of the command prompt window.
- REGEDIT: Edit keys in the Windows registry (use with caution).
- ROBOCOPY: A powerful file copy utility built right into Windows.
If you’re interested in learning more, Microsoft offers a full list of all of the Windows CMD commands included in the latest version of the Windows OS.
You will also like:
- Hilton hotels auburn al
- Luxe cake gold dust
- Biker hotline miami
- Metal edge tile
- Indeed jobs kansas
- Comcast service technician salary