Windows Troubleshooting just got a whole lot easier with the right Command Prompt commands. The "dir" command is a lifesaver, allowing you to view a list of files and subdirectories in a specified directory.
You can use the "chkdsk" command to scan your hard drive for errors and fix them automatically. This is especially useful if your computer is taking a long time to boot up or you're experiencing strange errors.
The "sfc" command scans your system files and replaces any corrupted ones with a fresh copy from the Windows installation media. This can be a game-changer if you're experiencing system file corruption issues.
Disk and File Management
Managing your files and disks efficiently is crucial for maintaining a smooth and organized system. You can use the del command to permanently delete files, but be careful as it's irretrievable. The /p parameter can be used to prompt for confirmation before deleting a file.
The xcopy command is a powerful tool for copying files, directories, and subdirectories. It can copy entire directory trees, including system and hidden files, using the /s parameter. If you want to include empty directories, use the /e parameter.
Here are some essential disk management commands:
The diskpart command is a disk partitioning tool that allows you to create, delete, and format partitions. You can also use it to manage volumes and delete, create, format, extend, and shrink volumes.
Defrag
Defrag is a command that finds and aggregates fragmented files on your system, reducing unnecessary empty data blocks and improving system performance.
The defrag command is used to defragment the C:\ drive, and it can be run with optional parameters like /u for progress updates and /v for a verbose output.
To defragment your C:\ drive, you'll need to run the defrag command with the correct syntax.
The defrag command reduces fragmentation by aggregating fragmented files, which can lead to improved system performance and faster access to files.
Del and Erase
Deleting files can be a delicate process, and it's essential to be cautious not to accidentally delete important files.
The del and erase commands are used to delete one or more files. Both commands permanently delete the specified file or files from a disk and are irretrievable.
To delete a file, you can use the del command followed by the file name, like so: del sample.txt. Alternatively, you can use the erase command with the same syntax: erase sample.txt.
To avoid accidental deletion, it's a good idea to use the /p parameter, which will prompt you for confirmation before deleting the file. This is especially useful when working with large numbers of files.
If you're unsure about deleting a file, it's always best to err on the side of caution and seek confirmation before proceeding.
Diskpart
Diskpart is a powerful tool for managing disk partitions, allowing you to create, delete, and format partitions. It's a must-know for anyone who wants to optimize their system performance and organization.
You can access the diskpart interface by entering the diskpart command in the Windows CMD. Once in diskpart, you can use various commands to manage your partitions.
Some essential diskpart commands include:
- list disk: Displays all the disks on your computer.
- select disk [number]: Selects the disk where you want to perform operations.
- clean: Removes all partitions from the selected disk.
With diskpart, you can also delete, create, format, extend, and shrink volumes, making it a versatile tool for disk management.
Mklink
The mklink command is a powerful tool for creating links to files and directories. It requires administrator privileges to run.
You can use the mklink command to create a symbolic link to a file by itself, like this: mklink. To create a hard link instead, you need to add the /h parameter.
To create a symbolic link to a directory, you can use the /d parameter with the mklink command. For example, mklink /d Docs.
The dir command will show the links in the directory listing. You can then use the cd command to enter the directory, treating the link as a regular directory, just like you would with a folder named Docs.
Md and Mkdir
Md and Mkdir are two essential commands for creating new directories in Windows CMD. They are often used interchangeably, but md is a shorthand for mkdir.
To create a new directory, you can use the mkdir command, which creates a directory in the current directory. For example, if you're in the c:\it folder and you type mkdir folder1, it will create folder1 in the c:\it folder.
The mkdir command can also create a directory tree by specifying multiple levels of subdirectories. For instance, mkdir folder1\folder2\folder3 will create folder3 as a subdirectory of folder2, which is a subdirectory of folder1.
You can also use the md command, which is a shorthand for mkdir and creates the same result. The command extensions enable both md and mkdir to create a directory tree, making it easy to create multiple levels of subdirectories with a single command.
Here are some key facts to keep in mind:
- md and mkdir are used to create new directories in Windows CMD.
- mkdir creates a directory in the current directory.
- mkdir can create a directory tree by specifying multiple levels of subdirectories.
- md is a shorthand for mkdir and creates the same result.
Move
The move command is a powerful tool for transferring files or directories from one location to another. It's a simple yet effective way to rename a file if the source and destination locations are the same but have different file names.
For example, the command move sample_file.txt file.txt will rename the file named sample_file.txt to file.txt. This is a great way to quickly give a file a new name without having to delete the old one.
The move command can also be used to provide the full path to move a file to another location, which is especially useful when working with files in different directories. Just make sure to specify the full path to the destination file, and the move command will take care of the rest.
Here are some key things to keep in mind when using the move command:
- The source and destination are either a folder or a file.
- The move command renames a file if the source and destination locations are the same but have different file names.
- When overwriting an existing file, the command prompts for confirmation unless the command runs as part of a batch script.
By using the move command effectively, you can streamline your file management tasks and save time in the long run.
Rmdir
The rmdir command is a powerful tool for deleting directories. It's a simple yet effective way to remove empty directories from your system.
To delete a directory, you can use the rmdir command followed by the directory path. For example, if you want to delete the c:\it\private directory, you can simply type rmdir c:\it\private.
The rmdir command will only delete empty directories by default. If you want to delete a directory and all its contents, you'll need to use the /s switch. This will delete the entire subdirectory tree and all files within it.
You can use the rmdir command to delete directories on any drive, including your system drive. Just be careful not to delete any important files or directories by mistake!
Here are some key things to know about the rmdir command:
- Deletes empty directories by default
- Uses the /s switch to delete directories and all their contents
- Can be used on any drive, including the system drive
Remember to use the rmdir command with caution and always double-check the directory path before deleting it.
Sort
The sort command is a powerful tool for organizing data. It allows you to sort provided data from a file or user input, and additional options control the sorting mechanism.
You can use the sort command interactively, which means you can sort data as you type it. To do this, simply follow the instructions in the manual.
The sort command can also be used on files, which is useful for organizing large amounts of data. This is done by simply typing the command and specifying the file you want to sort.
The command sorts the file contents and prints the result to the console. This can be a big help when trying to make sense of a large dataset.
Type
The type command is a simple yet useful tool for previewing files directly in the Command Prompt.
To use it, you just need to type "type" followed by the name of the file you want to view. For example, to show the contents of a file called sample_file.txt, you would run "type sample_file.txt".
The contents of the file will then be printed directly to the command line, allowing you to quickly preview the file without having to open it in a separate program.
This is especially useful when you're working with large files or need to quickly scan the contents of a file to see if it's what you're looking for.
Path
The path to finding the right files on your computer is by modifying the PATH environment variable. The PATH variable contains a set of directories that point to executable files.
To see the current state of the PATH variable, simply type "path" in the command line. This will show you the list of directories currently set in the PATH variable.
You can add multiple locations to the PATH variable by separating each location with a semicolon (;). This is useful if you have programs installed in different directories and want to access them easily from the command line.
Compact
The compact command is a built-in feature that compresses files and folders to save disk space.
To compress a file, use the /c parameter and provide the file name, like this: compact /c sample_file_1.txt.
This command returns the file to its original state if you want to expand it again.
You can use the compact command to compress large files and directories, making it easier to manage your disk space.
The syntax for the compact command is compact with the /c parameter and the file name.
Fc
The fc command is a powerful tool for comparing files. It displays the difference between two or more files, making it easy to identify changes.
To use fc, you can compare two files at a time, such as ping1.txt and ping2.txt. The command prints the file contents, indicating a difference between the two files.
The syntax for fc is straightforward, and you can use it to compare multiple files at once. For example, you can compare sample_file_1.txt and sample_file_2.txt to see their differences.
Label
Labeling your disk can be a great way to keep track of your files. The label command shows the label for the C:\ drive and starts a prompt to change the name.
To change or remove the label, you'll need administrator privileges. Without any options, the label command shows the label for the C:\ drive and starts a prompt to change the name.
Press Enter to remove the label, or enter a new name to change the current label name. Confirm the change with Y or press N to keep the existing name.
Remember to be careful when changing or removing labels, as it can affect how your computer recognizes the disk.
Makecab
The makecab command is a powerful tool for creating cabinet files on Windows systems.
These files are an archive format that supports lossless data compression and archive integrity.
To create a .cab file, use the makecab command with the following syntax.
You can create a cabinet file in the current directory and add files to the archive using this command.
For example, to create a sample_cab.cab file and add a sample_file.txt file, use the command as shown in the example.
The output will show the compression progress and exit when the process is complete.
Whoami
The whoami command is a handy tool for getting information about the current user. It's like a quick snapshot of who you are on the system.
You can use the whoami command without any options to show your current domain and username. This is the default behavior.
Adding the /all parameter to the whoami command gives you a more detailed view of the current user. You'll see the user's name, security ID, groups, and privileges.
If you're trying to get all the user accounts from the domain controller, the whoami command can help with that too. It's a useful tool for administrators who need to manage user accounts.
You can also use the whoami command to display the user name in UPN format. This is a unique identifier for the user that includes the domain name.
The whoami command can also show you the current domain, username, and user's SID. This can be helpful for troubleshooting issues related to user permissions.
Displaying all information for the current user is just one more thing the whoami command can do. It's a versatile tool that's worth getting familiar with.
Network Configuration and Diagnostics
The ipconfig command displays all current TCP/IP network configuration values and refreshes Dynamic Host Configuration Protocol (DHCP) and Domain Name System (DNS) settings. This is useful for troubleshooting or setting up new network connections.
Some other useful network configuration commands include ping, which tests the ability to reach a specific network device, and tracert, which traces the path that a packet takes to reach a network host. This helps identify where problems are occurring in the network.
Here are some essential network configuration and diagnostics commands:
- ipconfig: Displays all current TCP/IP network configuration values and refreshes DHCP and DNS settings.
- ping: Tests the ability to reach a specific network device.
- tracert: Traces the path that a packet takes to reach a network host.
- netstat: Displays active connections, ports, Ethernet statistics, and the IP routing table.
- nslookup: Queries the DNS to obtain domain name or IP address mapping.
- netsh: Allows configuration of almost any aspect of network settings.
- arp -a: Displays current ARP entries by interrogating the current protocol data.
- hostname: Shows the computer’s network name, aiding in network identification and troubleshooting.
- pathping: Combines the features of ping and tracert, providing more detailed information about network routes and latency.
Robocopy
Robocopy is a powerful tool for copying files and directories. The syntax for the command is straightforward.
The main benefit of using robocopy is the /mt parameter for higher-performance multithreading. This allows for faster file transfers.
The /z parameter lets you restart a transfer in case of interruptions. This is especially useful for large file transfers that are sensitive to interruptions.
Robocopy is a very popular Windows command for moving file servers to another server. It's also useful for copying files from one server to another.
To copy all files and folders to a new location, you can use the robocopy command. Alternatively, you can use Xcopy, another Windows command used for copying files and folders.
Get MAC Address
Getting the MAC address of a computer is a crucial step in network configuration and diagnostics. You can use the getmac command to retrieve the MAC address of all network cards on the computer or in the network.
The getmac command displays the MAC address and network transport protocols associated with each MAC address. For example, to show the MAC addresses in the CSV format, use the command with the /v option: getmac /v.
To run the getmac command on a remote computer, use the /s parameter. This is useful when you need to troubleshoot a client connection issue and verify the computer's MAC address on the switch.
Here's a quick reference guide to the getmac command:
The getmac command is a powerful tool for network troubleshooting and diagnostics. It's often used to parse the MAC address to a network monitoring tool or to check the protocols on network adapters.
Ipconfig
The ipconfig command is a powerful tool for network troubleshooting and configuration. It displays all current TCP/IP network configuration values and refreshes DHCP and DNS settings.
To show the basic TCP/IP configuration for all adapters, simply type "ipconfig" in the command prompt and press enter. This will give you a quick overview of your network settings.
The ipconfig command can also be used to troubleshoot connectivity issues. By using the "/all" switch, you can display the full TCP/IP configuration for all network cards on your computer.
Here are some additional ipconfig commands you can use:
These commands can be useful for troubleshooting network connectivity problems or when changes to the network configuration are required. For example, the "/flushdns" command can help resolve DNS-related issues by forcing the system to discard outdated information and fetch the latest DNS data.
The ipconfig command is also useful for displaying the current ARP entries by interrogating the current protocol data. This can be done using the "arp -a" command, which shows the IP address and matching MAC address.
Remember, the ipconfig command is a versatile tool that can be used for a variety of network-related tasks. By mastering its various switches and options, you can become more proficient in network troubleshooting and configuration.
Net
The net command is a powerful tool for managing network resources and services. It's used to connect to network shares, such as network drives and printers, and can also be used to disconnect from them.
To connect to a network share, you can use the net use command, as seen in example 2. This command allows you to map a network drive to a server, in this case, srv-vm1. You can also use net use to list all available network resources.
To stop a service, such as the printer spooler service, you can use the net stop command, as seen in example 7. This command is useful for troubleshooting or when you need to restart a service.
The net user command, as seen in example 8, is used to display user account information on a local computer or the domain. This command is useful for network administrators who need to manage user accounts.
Here are some examples of net commands and their uses:
The netstat command, as seen in example 9, is used to display network statistics and information about network connections, routing tables, and interface-related data. This command is useful for monitoring network activities and troubleshooting network-related issues.
Nslookup
Nslookup is a powerful tool for querying DNS records and troubleshooting DNS issues. It's a must-have command for any sysadmin or network engineer.
Nslookup can be used to check DNS records and verify that DNS is working correctly. You can use it to check PTR, A, MX, SOA, and many other types of DNS records.
The syntax for nslookup is straightforward: simply type in the domain name you want to look up, and the output will print the A records for the provided domain. Without any options, nslookup enters interactive mode, allowing you to look up additional data.
Nslookup is an essential tool for network troubleshooting, and it's especially useful when you need to verify that DNS is working correctly. For example, if you're having trouble accessing a website, you can use nslookup to check the DNS records for the website and see if there are any issues.
Nslookup can also be used to perform various tests to verify DNS functionality, making it a valuable asset for any network administrator. It's another one of my favorite Windows commands for network troubleshooting.
Route
The route command is a powerful tool for network configuration and diagnostics. It's used to show and alter entries in the local routing table.
The command syntax is: route [command] [destination]
Available commands include: add, change, delete, and print. For example, to print all routes from the table, use: route print.
The output shows the interface list, as well as the IPv4 and IPv6 routing tables.
To view the local computer's routing table, use the route print command. This is useful when the computer has multiple network interface cards and you need to determine the route network traffic is taking.
Here's a breakdown of the route print command options:
For example, to print only the IPv4 routing table, use: route print -4
The route command is a valuable tool for network administrators and users alike. It helps diagnose network latency and routing issues, and can be used to troubleshoot connectivity problems.
Tree
The tree command is a useful tool for displaying directory structures. It's especially helpful when you need to visualize the contents of a drive or directory.
The syntax for the tree command is straightforward: it can be used without options to display the directory structure of a specific drive, such as the C:\ drive. This can be a quick way to get an overview of what's inside a drive.
Hostname
The hostname command is a simple yet useful tool for network configuration and diagnostics.
You can use the hostname command to display a machine's host name, which is the name of the current machine.
The command does not require any options, but providing additional parameters will result in an error.
The hostname command is available for systems with TCP/IP installed on a network adapter.
In Windows, the hostname command is useful for displaying the host name of the computer.
You can run the hostname command to see the name of the current machine, and it's a good idea to do this to verify the host name of your system.
The hostname command is a basic yet essential tool for anyone working with network configuration and diagnostics.
Mstsc
The mstsc command is a powerful tool for remote desktop connections. It allows you to connect to a remote machine or edit an existing .rdp file.
To start an RDC session in full-screen mode, use the mstsc command with the right parameters. This can be super helpful when you need to access a remote computer.
You can use the mstsc command to connect to a server using full screen, which is especially useful when working with multiple monitors. For instance, use 192.168.100.10 as the server address.
To span the RDP connection across multiple monitors, use the mstsc command with the right settings. This can greatly enhance your productivity when working remotely.
Telnet
The telnet command is a Windows tool for bidirectional CLI communication. It uses the Telnet protocol to send messages and enable an interactive communication channel with remote devices.
You can use the telnet command to ping a specific port on Windows. The command prints the current time and returns to the command line.
I use the Windows telnet client to test if a remote host is allowing connection on a specific port. This is typically done when someone says your firewall is blocking a program from working.
If you know the port number the application runs on, you can use the command below. For example, if you installed FileZilla server, port 21 should be open.
The syntax is telnet + hostname or IP + port number. You may or may not get a response back from the remote server.
If it doesn’t get a connection, you should get a message like the below. The telnet client is simple to use, but it's a powerful tool for troubleshooting network issues.
Timeout
Timeouts are essential in network configuration and diagnostics, allowing you to pause the command line for a specified number of seconds.
The timeout command pauses the command line for a specified number of seconds, giving you time to execute another command or make adjustments. The syntax for the command is a key part of using it effectively.
To pause the interpreter for a short period, you can use the timeout command with a specified number of seconds. For example, to pause the interpreter for ten seconds, run: timeout 10.
Pressing any key interrupts the timeout earlier, allowing you to regain control of the command line. This is especially useful when working with scripts that need to wait for execution between two commands.
Vol
The vol command is a simple yet useful tool for getting information about your system's disk drives. It prints the disk volume label and serial number.
To use the vol command, you'll need to know its syntax: vol [drive]. Without a specified drive, the vol command shows information for the currently selected drive.
This command can be particularly helpful when you're troubleshooting issues with your disk drives. I've used it myself to double-check the serial number of a drive that was causing problems.
Where
Network configuration and diagnostics often involve understanding the physical and logical locations of devices and connections. A network's physical location can impact its performance and security.
The physical location of a network device can affect its connectivity and signal strength. In a home network, for example, a Wi-Fi router placed in a central location can improve coverage.
Network devices can be connected in various ways, including through Ethernet cables or wireless connections. The type of connection used can impact the network's speed and reliability.
In a small office network, a switch can be used to connect multiple devices to a single router. This can help increase the network's bandwidth and reduce congestion.
Dcdiag
If you're an administrator of Active Directory, you should know the dcdiag command. It analyzes the state of your domain controllers with over 30 built-in tests.
Running dcdiag at regular intervals ensures your domain environment remains healthy. This is crucial for maintaining a stable network.
To run dcdiag on a specific domain controller, use the command with the domain controller's name. This allows you to pinpoint any issues specific to that controller.
Cls
The cls command is a simple yet effective tool for clearing the text in a command prompt window. It clears the screen contents and returns a blank surface.
You can use the cls command to clear the screen and start fresh. Note that the previous contents and output cannot be restored.
The cls command is a quick way to clear your screen and get back to work.
Frequently Asked Questions
What is the best command in cmd?
The most versatile command in cmd is likely "CD" (Change Directory), as it allows you to navigate and manage your system's directories with ease. However, the best command for you will depend on your specific needs and goals.
How do I list all commands in cmd?
List all commands in cmd by typing 'Help' and pressing Enter. This will display a list of available commands, or type a specific command followed by '/?' for more information
What should I write in cmd?
To create subdirectories, use "mkdir". For other tasks, refer to the list of available commands.
Sources
Featured Images: pexels.com