Diff: Command Prompt
Comparing revision #2 (2024-03-02 21:47:37) with revision #3 (2026-06-22 13:11:07).
| Old | New |
|---|---|
'''Command Prompt (Cmd)''' is a command-line interpreter that comes with [[Microsoft Windows]]. It allows users to execute commands to perform various tasks, such as managing files and directories, running programs, and configuring system settings. Command Prompt is often used for troubleshooting, system administration, and automation tasks. Here's an in-depth look at how Command Prompt works and its capabilities. |
|
'''Command Prompt''' is the traditional command-line interpreter included with [[Microsoft Windows]]. It is commonly opened through <code>cmd.exe</code> and is also known as the Windows Command Processor. |
|
== Overview == |
|
Command Prompt is a text-based interface that allows users to interact with the Windows operating system. It provides a way to navigate through directories, manipulate files, and run commands and programs. Command Prompt supports a wide range of commands and utilities, allowing users to perform tasks such as: |
|
Command Prompt lets a user run text commands to manage files, start programmes, inspect network settings, run scripts and perform administrative tasks. It remains useful even though Windows PowerShell and Windows Terminal provide newer command-line experiences. |
|
* Creating and deleting directories (<code>mkdir</code>, <code>rmdir</code>) |
|
* Managing files and directories (<code>dir</code>, <code>del</code>, <code>copy</code>, <code>move</code>, <code>rename</code>) |
|
* Running programs (<code>start</code>, <code>taskkill</code>, <code>tasklist</code>, <code>wmic</code>) |
|
* Managing system settings (<code>shutdown</code>, <code>net</code>, <code>ipconfig</code>, <code>reg</code>, <code>powercfg</code>) |
|
== Purpose == |
|
Command Prompt provides a text interface to Windows. Instead of clicking through menus, a user enters commands and receives text output. |
|
== Usage == |
|
To open Command Prompt, users can press <code>Windows Key + R</code> to open the Run dialog, then type <code>cmd</code> and press Enter. Alternatively, users can search for "Command Prompt" in the Start menu. Once Command Prompt is open, users can type commands and press Enter to execute them. Commands typically consist of the command name followed by any necessary parameters or options. Some commands require administrator elevation, such as sfc or diskpart, so you will need to run cmd as administrator. |
|
Common uses include: |
|
== Syntax == |
|
Command Prompt commands typically follow a common syntax: |
|
* Listing, copying, moving or deleting files. |
|
* Running diagnostic tools such as <code>ping</code> and <code>ipconfig</code>. |
|
* Starting programmes or scripts. |
|
* Managing environment variables. |
|
* Running batch files. |
|
* Troubleshooting Windows installations and recovery environments. |
|
Here's a breakdown of the elements: |
|
== Opening Command Prompt == |
|
Command Prompt can be opened from the Start menu, the Run box, Windows Terminal, File Explorer's address bar, or administrative tools. |
|
* <code>command-name</code>: The name of the command being executed. |
|
* <code>parameters</code>: Additional information provided to the command, such as filenames or directory paths. |
|
* <code>options</code>: Additional settings or flags that modify the behavior of the command. |
|
Some commands require an elevated session. An elevated Command Prompt is one opened with administrator rights. Commands that change system files, disk layout, boot configuration or protected settings may fail without elevation. |
|
== Examples == |
|
Let's look at some examples of Command Prompt commands: |
|
== Basic Syntax == |
|
Most commands follow a simple pattern: |
|
* <code>dir</code>: Lists the contents of the current directory. |
|
* <code>cd Documents</code>: Changes the current directory to "Documents." |
|
* <code>copy file1.txt file2.txt</code>: Copies "file1.txt" to "file2.txt." |
|
* <code>del file.txt</code>: Deletes "file.txt." |
|
<code>command option target</code> |
|
== Customisation == |
|
Command Prompt can be customised to change its appearance and behaviour. Users can modify settings such as the font size and colour, the window size, and the default directory. Additionally, Command Prompt supports batch scripting, which allows users to write scripts that automate tasks by executing a series of commands. |
|
Examples include: |
|
== Scripting == |
|
Command Prompt supports batch scripting, which allows users to write scripts that automate tasks by executing a series of commands. Batch scripts are text files that contain a sequence of Command Prompt commands. When executed, a batch script runs each command in order. |
|
* <code>dir</code> lists files and folders. |
|
* <code>cd</code> changes the current directory. |
|
* <code>copy source destination</code> copies a file. |
|
* <code>del filename</code> deletes a file. |
|
* <code>ipconfig</code> displays network configuration. |
|
* <code>tasklist</code> lists running processes. |
|
Here's an example of a simple batch script that lists the contents of a directory and then deletes a file: |
|
Spaces matter. File paths that contain spaces should be wrapped in quotation marks, such as <code>"C:\Users\Public\Documents"</code>. |
|
<code>@echo off</code> |
|
== Batch Files == |
|
Command Prompt can run batch files, usually ending in <code>.bat</code> or <code>.cmd</code>. A batch file is a text file containing commands that run in order. |
|
<code>dir</code> |
|
Batch files are still used for simple automation, login scripts, legacy administration and compatibility with older tools. For complex automation, PowerShell is usually more capable because it works with structured objects and has a larger scripting language. |
|
<code>del file.txt</code> |
|
== Safety == |
|
Command Prompt can delete files, change system settings and run programmes. A command copied from an unknown source should be read before it is run. |
|
This script turns off echoing, which prevents the commands from being displayed as they're executed. Then it lists the contents of the current directory and deletes "file.txt." |
|
Particular care is needed with commands such as <code>del</code>, <code>rmdir</code>, <code>format</code>, <code>diskpart</code>, <code>bcdedit</code> and scripts that download and run remote code. |
|
== Best Practices == |
|
When using Command Prompt, it's important to follow best practices to ensure that commands are executed correctly and safely: |
|
== Relationship to MS-DOS == |
|
Command Prompt is sometimes casually called a DOS prompt, but modern <code>cmd.exe</code> is not MS-DOS. It is a Windows command interpreter descended from earlier command-line environments and used on Windows NT-based systems. |
|
* Double-check commands: Before executing a command, make sure it's correct. A typo could result in unintended consequences. |
|
* Be cautious with administrative commands: Some commands, such as those that modify system settings or delete files, require administrative privileges. Always confirm before running these commands. |
|
* Use quotes for filenames with spaces: If a filename contains spaces, enclose it in double quotes to prevent issues. |
|
* Understand command syntax: Familiarise yourself with the syntax of Command Prompt commands to ensure they're used correctly. |
|
* Backup important files: Before running commands that modify or delete files, it's a good idea to make a backup of important files to avoid data loss. |
|
== See Also == |
|
* [[Microsoft Windows]] |
|
* [[PowerShell]] |
|
* [[MS-DOS]] |
|
* [[Malware]] |
|
== Conclusion == |
|
Command Prompt is a powerful tool for interacting with the Windows operating system. By using a combination of built-in commands and utilities, users can manage files and directories, run programs, and configure system settings. Understanding how to use Command Prompt effectively can be a valuable skill for troubleshooting, system administration, and automation tasks. |
|
== References == |
|
* [https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands Microsoft Learn: Windows commands] |
|
* [https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cmd Microsoft Learn: cmd] |
|
* [https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/cc754340(v=ws.11) Microsoft Learn: Command-line reference] |
|
[[Category:Microsoft Windows]] |
|
[[Category:Computing]] |