Windows Command Prompt: How to Use and Basic Commands
In this article
The Windows Command Prompt (CMD) is a command-line interpreter application that allows you to interact with your computer by typing text-based commands instead of clicking icons in a graphical user interface. You can use it to automate repetitive tasks, troubleshoot network connectivity, manage files and folders, and access system tools that are not available through the standard Windows Settings menus. To start, simply type "cmd" into the Windows search bar and press Enter.
What You'll Need
- A computer running a version of Microsoft Windows.
- Administrative privileges (required for certain system-level commands).
- A keyboard for entering text commands.
Step-by-Step
- Open the Command Prompt: Click the Start button or press the Windows key on your keyboard. Type "cmd" into the search field. You will see "Command Prompt" appear in the results. Depending on the task, you may need to right-click the result and select "Run as administrator" to grant the program permission to modify system files. Labels and search result layouts may differ slightly based on your version of Windows.
- Understand the Command Prompt Interface: Once open, you will see a black window with white text. The text usually shows a file path, such as
C:\Users\YourName>. This is called the "prompt." It tells you which folder (directory) you are currently working in. Any command you type will be executed within that specific folder unless the command is designed to affect the entire system. - Navigating Folders (Directories): To move between folders, use the
cd(Change Directory) command. For example, to move into a folder named "Documents," typecd Documentsand press Enter. To move back up one level to the parent folder, typecd ..and press Enter. If you need to switch to a different drive entirely, such as the D: drive, simply typeD:and press Enter. - Listing Files and Folders: To see what is inside your current folder, use the
dircommand. Typedirand press Enter. The Command Prompt will list all files and subfolders, along with their sizes and the date they were last modified. This is the text equivalent of opening a folder in File Explorer. - Creating and Deleting Folders: To create a new folder, use the
mkdir(Make Directory) command. For example, typemkdir MyNewFolderand press Enter. To delete an empty folder, use thermdir(Remove Directory) command, such asrmdir MyNewFolder. Note thatrmdirwill not work if the folder contains files; you must delete the files inside first. - Managing Files: To rename a file, use the
rencommand. Typeren oldname.txt newname.txt. To delete a file, use thedelcommand. For example,del document.txtwill permanently remove that file. Be cautious, as files deleted via Command Prompt typically do not go to the Recycle Bin. - Network Troubleshooting: One of the most common uses for CMD is checking internet connectivity. Type
ping google.comand press Enter. This sends small packets of data to the server to see if it responds. If you see "Reply from...", your connection is working. If you see "Request timed out," there is a connection issue. Another useful command isipconfig, which displays your computer's current IP address and network gateway information. - System File Checks: If your computer is behaving strangely, you can use the System File Checker. This requires administrative privileges. Type
sfc /scannowand press Enter. Windows will scan all protected system files and replace corrupted versions with correct Microsoft versions. This process can take several minutes to complete. - Closing the Prompt: Once you have finished your tasks, you can close the window by clicking the "X" in the top right corner or by typing
exitand pressing Enter.
Common Mistakes
One of the most frequent errors is forgetting to run the Command Prompt as an administrator. Many powerful commands, such as sfc /scannow or commands that modify the C:\Windows directory, will return an "Access Denied" error if you are running the prompt as a standard user. Always check the title bar of the window; it should say "Administrator: Command Prompt" if you have elevated privileges.
Another common mistake is typing file or folder names with spaces without using quotation marks. For example, if you try to enter a folder named My Projects by typing cd My Projects, the system will think you are trying to run two separate commands. To fix this, wrap the path in quotes: cd "My Projects".
Users also frequently confuse the dir and cd commands. Remember that dir is for looking at what is there, while cd is for moving into a specific location. You cannot cd into a file; you can only cd into a folder.
Tips
To speed up your workflow, use the Tab key for "Auto-complete." Instead of typing a long folder name like cd Documents_Backup_2023, you can type cd Doc and press Tab. Windows will automatically fill in the rest of the name for you. If there are multiple folders starting with "Doc," keep pressing Tab to cycle through them.
If you need to run a long series of commands, you can create a "Batch file." Open Notepad, type your commands on separate lines, and save the file with a .bat extension (e.g., myscript.bat). Double-clicking this file will execute all the commands in sequence automatically.
To clear the screen when it becomes cluttered with too much text, type cls and press Enter. This wipes the visible history and gives you a clean slate at the top of the window without closing the session.
You can redirect the output of a command to a text file instead of displaying it on the screen. For example, typing ipconfig > network_info.txt will create a file named "network_info.txt" containing all the details that would normally appear in the window. This is very useful for logging system data for later review.
Troubleshooting
If you receive an error stating "'command' is not recognized as an internal or external command, operable program or batch file," it usually means one of two things. First, you may have a typo in the command. Double-check your spelling and spacing. Second, the program you are trying to run is not in the Windows "System Path." The Path is a list of directories that Windows searches through to find executable files. If a program is installed in a custom folder, you must either cd into that specific folder first or add that folder to the system environment variables in the Windows Control Panel.
If the Command Prompt freezes or stops responding while running a process (like a large file copy or a system scan), you can usually force the command to stop by pressing Ctrl + C. This sends an interrupt signal to the current process and returns you to the command prompt.
If you cannot find the Command Prompt in the search menu, you can open it manually. Press Windows Key + R to open the Run dialog, type cmd, and press Enter. If this also fails, ensure that your user account has permission to access system tools, or contact your system administrator if you are on a managed work computer.
Frequently Asked Questions
Is Command Prompt the same as PowerShell?
No. While both are command-line tools, PowerShell is more advanced and uses a different language (Cmdlets) designed for complex system administration and automation, whereas CMD is a legacy tool for basic tasks.
Can I undo a command in CMD?
Generally, no. There is no "Undo" button for commands like del or rmdir. Once a file is deleted via the command line, it is typically removed permanently and does not go to the Recycle Bin.
How do I run a command as an administrator?
Search for "cmd" in the Start menu, right-click on "Command Prompt," and select "Run as administrator." A User Account Control (UAC) prompt will appear asking for confirmation.
What does the "ping" command actually do?
It sends a small packet of data (ICMP echo request) to a specific IP address or domain to check if the destination is reachable and to measure how long it takes for the data to return.
How do I see a list of all available commands?
You can type help and press Enter to see a list of the most common built-in commands and a brief description of what each one does.
Can I use CMD to recover deleted files?
CMD itself cannot "undelete" a file, but it can be used to run official Microsoft tools like attrib to reveal hidden files that may have been hidden by malware or system errors.