Windows CMD Commands
The Command Prompt is a powerful tool in the Windows operating system. It provides a text-based interface for interacting with the computer.
By understanding and utilizing various CMD commands, you can automate tasks, troubleshoot issues, and perform advanced system administration.
This tutorial covers 40 Windows CMD Commands to let you get familiar with the basic and advanced commands you would need most.
Complete List of Windows CMD Commands
After buying Windows VPS, you need to manage it by mastering the command line.
Here’s your comprehensive guide to essential Windows CMD commands, empowering you to automate tasks.
Consider that having administrator privileges and access to the command prompt is essential to follow this guide.
Windows CMD Commands for File and Directory Management
1. dir
- Function: Displays information about files and subdirectories within the specified directory, including their names, size, date and time of creation or modification, and attributes.
- Syntax:
dir [path]
- Example:
dir C:\Users\YourName
2. md
- Function: Create a new directory (folder). It takes the name of the new directory as an argument.
- Syntax:
md [directory name]
- Example:
md Documents\Projects
3. rd
- Function: Removes (delete) a directory (folder). It takes the name of the directory to be deleted as an argument.
- Syntax:
rd /s /q [directory name]
- Example:
rd /s /q Temp
4. copy
- Function: Duplicate files or directories. It can be used to copy individual files or entire directories and their contents.
- Syntax:
copy [source file] [destination]
- Example:
copy important.txt C:\Backup
5. move
- Function: Relocate files or directories to a new location. It can be used to move files between different directories or even between different drives.
- Syntax:
move [source] [destination]
- Example:
move old_file.txt new_file.txt
6. del
- Function: Delete files or directories. It can be used to delete individual files or entire directories and their contents.
- Syntax:
del [filename]
- Example:
del *.tmp
7. attrib
- Function: Displays or changes file attributes (read-only, hidden, system, archive). It can be used to make files read-only, hidden, or system files, or to remove these attributes.
- Syntax:
attrib [options] [filename]
- Example:
attrib +h important.txt (sets the "hidden" attribute for important.txt)
8. robocopy
- Function: Robust file copying utility with advanced features. It offers advanced features like mirroring directories, filtering files based on attributes or time stamps, and resuming interrupted transfers.
- Syntax:
robocopy [source] [destination] [options]
- Example:
robocopy C:\Backup D:\Archive /mir
9. xcopy
- Function: Copies files and directories with various options. It offers more advanced features than the basic copy command, such as copying subdirectories, excluding specific files or directories, and verifying the integrity of the copied files.
- Syntax:
xcopy [source] [destination] [options]
- Example:
xcopy *.* D:\Backup /d
10. subst
- Function: Creates a virtual drive letter for a directory. It allows you to access a directory as if it were a separate drive.
- Syntax:
subst [drive letter] [path]
- Example:
subst Z: C:\Users\YourName\Documents
11. junction
- Function: Creates a symbolic link to a directory. It allows you to link two directories together. So that changes made to one directory are automatically reflected in the other.
- Syntax:
junction [target] [source]
- Example:
junction C:\link D:\data
12. linkd
- Function: Creates a symbolic link. It is similar to the junction command but provides additional flexibility and options for creating junction points.
- Syntax:
linkd [target] [source]
- Example:
linkd C:\link D:\data
Windows CMD Commands for System Information and Configuration
13. systeminfo
- Function: Displays system information about the computer system, including hardware specifications, operating system details, and network configuration.
- Syntax:
systeminfo
- Example:
systeminfo /fo csv > systeminfo.csv
14. ipconfig
- Function: Displays network configuration of the computer, including IP addresses, subnet masks, default gateways, and DNS server addresses.
- Syntax:
ipconfig /all
- Example:
ipconfig /all > ipconfig_output.txt
15. ping
- Function: Tests network connectivity by sending ICMP echo requests to a specified host and waiting for replies. It provides information about the round-trip time, packet loss, and other network metrics.
- Syntax:
ping [IP address or hostname]
- Example:
ping google.com
16. tasklist
- Function: Lists running tasks on the computer, including their process ID, name, and CPU and memory usage.
- Syntax:
tasklist
- Example:
tasklist /v > tasklist_output.txt
17. taskkill
- Function: Ends a running task on the computer, either by process ID or by process name.
- Syntax:
taskkill /pid [process ID]
- Example:
taskkill /pid 1234
Windows CMD Commands for Networking and Remote Access
18. netstat
- Function: netstat command displays network statistics including active connections, listening ports, and routing tables.
- Syntax:
netstat -a
- Example:
netstat -a > netstat_output.txt
19. route
- ّFunction: Displays or modifies the routing table on the computer, which determines how network traffic is sent to different destinations.
- Syntax:
route [options]
- Example:
route print
20. telnet
- Function: Connects to remote systems using the Telnet protocol. It is primarily used for administrative tasks and debugging network connections.
- Syntax:
telnet [hostname] [port]
- Example:
telnet localhost 23
21. ssh
- Function: Connects to remote systems securely using SSH. It provides a secure alternative to telnet by encrypting all data transmitted between the client and server.
- Syntax:
ssh [username]@[hostname]
- Example:
ssh [email protected]
22. tracert
- Function: Traces the route of packets to a destination. It displays the IP addresses of each hop along the path and the time it takes for packets to reach each hop.
- Syntax:
tracert [hostname or IP address]
- Example:
tracert google.com
23. arp
- Function: Displays or modifies the Address Resolution Protocol (ARP) cache which is used to determine the physical address of a device on the network.
- Syntax:
arp [options]
- Example:
arp -a
Windows CMD Commands for Performance and Optimization
24. perfmon
- Function: Monitors system performance and resource usage, providing detailed information about various performance counters.
- Syntax:
perfmon
25. defrag
- Function: Defragments hard drives. It reorganizes fragmented files to improve read/write performance and overall system speed.
- Syntax:
defrag [volume]
- Example:
defrag C:
26. cleanmgr
- Function: Launch the Disk Cleanup utility, which scans the system for files that can be safely deleted to free up disk space.
- Syntax:
cleanmgr
27. schtasks
- Function: Schedules tasks to run automatically at specific times or intervals. It can be used to schedule tasks to run daily, weekly, monthly, or even once.
- Syntax:
schtasks /create /tn "MyTask" /tr "C:\script.bat"
- Example:
schtasks /query
28. powercfg
- Function: Configures power settings on the computer, such as screen brightness, sleep timeout, and power plan options.
- Syntax:
powercfg <options> <arguments>
- Example:
powercfg /list
Windows CMD Commands for Security
29. netsh
- Function: Configures network settings on the computer, such as IP addresses, DNS servers, and firewall rules. It provides a flexible and powerful way to manage network interfaces and connections.
- Syntax:
netsh firewall show config
30. cacls
- Function: Changes access control lists (ACLs) for files and directories. It allows you to grant or deny permissions to specific users or groups, making it essential for securing your system.
- Syntax:
cacls [filename] /grant User:Read
31. icacls
- Function: Manages access control lists (ACLs) for files and directories, providing more advanced features and options than the
cacls
command - Syntax:
icacls [filename] /remove User
32. sc config
- Function: Configures service settings, including security options. It allows you to change the startup type, display name, and other settings for services that run in the background.
- Example:
sc config MyService start= auto
Miscellaneous Windows CMD Commands
33. color
- Function: Change the text color and background color in the command prompt window. It allows you to customize the appearance of the console for improved readability and visual preference.
- Syntax:
color [attributes]
- Example:
color 0A
34. timedate
- Function: Sets the system time and date. The
time
anddate
command can be used separately to set the system time and date. - Syntax:
timedate
35. pause
- Function: Pauses a batch file or script. It displays the message “Press any key to continue…” and waits for user input before resuming execution.
- Syntax:
pause
36. choice
- Function: Prompts the user for input and allows them to select from a predefined list of options. It displays a message and a list of choices and then waits for the user to enter a corresponding number or letter to select their choice.
- Example:
choice /c yn "Do you want to continue (y/n)?"
37. find
- Function: Searches for text within files. It can be used to locate specific words or phrases in a variety of file formats, including text files, HTML files, and more.
- Syntax:
find "[string]" [filename]
- Example:
find "error" log.txt
38. sort
- Function: Sorts the lines of text in a file alphabetically or numerically. It can be used to arrange data in a specific order, making it easier to analyze and process.
- Syntax:
sort [options] [filename]
- Example:
sort -r names.txt
39. type
- Function: Displays the contents of a file to the console. It is a simple but effective way to view the content of a file without opening it in a text editor.
- Syntax:
type [filename]
- Example:
type readme.txt
40. Findstr
- Function: Searches for text within files. It provides more advanced search capabilities than the
find
command, including regular expression matching and multiple search patterns. - Syntax:
findstr "string" [filename] [options]
- Example:
findstr "error" log.txt > error_log.txt
That’s it! You can use the help
command to get detailed information about a specific command.
How to Use CMD Commands on Windows?
To use a Windows CMD Command, follow the below path. [Using the Start Menu]
1. Open the Command Prompt:
To do this on Windows 10/11, search for “Command Prompt” in the Start menu and select it.
On older Windows versions, click on the Start button, go to “Run,” and type “cmd” into the dialog box.
2. Navigate to the Desired Directory:
Use the cd command to change the current directory.
For example, to navigate to the Documents folder:
cd Documents
3. Execute the Command:
Type the command, followed by any necessary options or arguments.
For example, to list the contents of the current directory:
dir
4. Interpret the Output:
The Command Prompt will display the results of the command. Pay attention to any error messages or information provided.
- Example:
To copy a file named “important.txt
” from the current directory to a new directory called “Backup,” you would use the following command:
md Backup
copy important.txt Backup
This will create a new directory named “Backup” and copy the “important.txt
” file to it.
Also, you can use the Run Dialog method to access Command Prompt on Windows:
- Press the Windows key + R simultaneously.
- Type “cmd” in the Run dialog box.
- Click OK or press Enter.
Why does Mastering Windows CMD matter?
By understanding and utilizing various CMD commands, you can automate tasks, troubleshoot issues, and perform advanced system administration.
Whether you’re a power user, a system administrator, or simply someone who wants to optimize their computer’s performance, mastering CMD will provide you with the tools and knowledge you need to achieve your goals.
How to delete a file or directory?
To delete a file, run:
del filename.txt
To delete a directory (including its contents), type:
rd /s /q directory_name
The Command Prompt (CMD) is a powerful tool for diagnosing and resolving common Windows issues.
Here are some effective techniques:
Check Event Logs:
- Identify the issue: Use
eventvwr
to view event logs and look for error messages related to the problem.
Utilize netstat and ping:
- Network troubleshooting: Use
netstat -a
to check network connections andping
to test connectivity to specific hosts.
Monitor System Resources:
- Use
tasklist
andperfmon
: Monitor running processes, CPU usage, memory consumption, and disk I/O to identify bottlenecks.
Check for Updates:
- Ensure up-to-date drivers and software: Use
Windows Update
to install the latest patches and updates.
How to troubleshoot Network Connectivity issues Using Windows CMD commands?
To test connectivity, run:
ping google.com
Then, check your network adapter settings and ensure it’s enabled and use the following command to resetting your network adapter:
netsh int ip reset reset.log
How to troubleshoot performance issues Using Windows CMD Command?
To view running processes and their memory usage, use tasklist
and run perfmon
to monitor system performance.
Conclusion
This article provides a comprehensive guide to essential Windows CMD commands. By mastering Windows command line, you can effectively manage your Windows system and automate various tasks.
It covers commands for file and directory management, system information, networking, performance, security, and miscellaneous tasks.
The examples and explanations for each command make it easy to understand and use.