In the Microsoft operating system it includes more and more options, functions,and adjustments so that the user himself can configure, personalize and manage his system as he wants. However, although for many users it is still a great unknown, Windows has what we know as a command prompt or CMD. It is nothing more than a command line from which we can do many of the things that we can do from the system’s own graphical interface and even others that we do not have within reach in that way. Next, we are going to show a window CMD guide with the most basic and useful commands to start using the Windows console.
What is command prompt or CMD and how to open it
CMD are abbreviations for CoMmanD and it is an equivalent Microsoft program command.com, the MSDOS command interpreter. So that everyone can understand it, it is a kind of command translator that uses the system itself so that it can interpret and execute them.
Users for whom the command prompt is a great stranger may be wondering where is this tool or program? Well, we must know that to open the CMD or the command prompt window, all we have to do is type “command prompt” or “cmd” in the search bar box of the taskbar and click in the application from the list of results or open a window run Windows, Win + R, type ” cmd ” and press enter or OK. In one way or another, a window will open automatically with the command line where we can start writing the commands that we want to execute in the system.
In some instances, we need administrator permissions to perform some system action, something that can happen to us from the command line as well. To run a CMD or a command prompt with administrator permissions, what we have to do is type “command prompt” or “CMD” in the taskbar search box, and then right-click the mouse to select Run as an administrator option.
CMD vs PowerShell
The CMD , command prompt or also known as Command prompt is a command line interpreter that has accompanied the Microsoft operating system for decades. So much so that it is the original shell for the Microsoft DOS operating system and the default shell in Windows until Windows 10 build 14791, at which point Windows Powershell became the default system option.
With the command prompt we can launch or execute basic commands, prepare relatively simple scripts, and perform many of the tasks that we can do from the graphical interface of the Microsoft operating system. Now, when we need to carry out more advanced developments, access certain areas of the system or automate tasks is where Windows PowerShell appears.
As Windows has advanced and evolved, Microsoft has also decided to incorporate a more modern and powerful tool to the CMD or command prompt. And it is that Windows PowerShell is a scripting language and advanced Shell written in the Microsoft .NET Framework and to which certain cmdlets have been added that allow performing tasks in the background or even remotely , as well as the automation of tasks . A tool more thought for system administrators and that is shaping up to be the logical replacement with the passage of time of CMD.
Basic knowledge and useful CMD commands
Once we are in front of the command prompt, we must know that there are certain commands and keys that will help us a lot in the use of the CMD, as well as to get the most out of it.
Basic CMD Commands
The first command that we must learn is the Help command. To run this command, all you have to do is type help on the command line and press Enter. Automatically, we will see how a list of the basic commands that we can use in the system console appears and what each one is for.
All the commands that we execute require that they have a correct syntax so that they execute without problems. Since we cannot memorize each and every one of these syntaxes, the CMD itself offers a command to query the syntax for using any command. To do this, all we have to do is write the command name, leave a space and then write the characters /? and press Enter. For example, if we want to know what is the correct syntax to use the cd command, which we will see later what it is for, we will have to execute cd / ?. Automatically, we will see how the correct syntax or syntax appears that allows us to use this command.
By default, the command prompt opens at the path C: Users username, however we may need to move to other folders or drives to perform the appropriate tasks. To do this, we are going to use the cd command, which allows us to move between folders. To enter inside a folder within the path we are on, all we have to do is run the command:
To go directly to a folder within that path without having to go through the previous folders we can execute:
If we want to return, on the other hand, to leave a directory and return to the one containing it, then the command cd .. is sufficient to run, whereas if the unit we are located at once will leave root, then we need to run CD.
If we have multiple partitions or drives on our disk, or if we have an internal storage device connected, and we want to go to that drive from the command prompt, all we have to do is type the letter of that drive followed by a colon and press Enter from the path where we are automatically selected, e.g. E:.
When we are in a certain path and we want to know the folders or files that are inside it, just as we can do from the file explorer in the Windows graphical interface, what we have to do is run the dir command. Automatically we will be shown by command line all the folders and files contained in the folder in which we are. To identify what a folder and a file are, just look at whether <DIR> appears in front of the name, which indicates that it is a directory or folder. If it is a file, the size of the file will appear to the left of the name.
With this command we delete everything that appears on the command line and it will be completely clean so that we can start again from scratch. Just type cls and hit Enter.
As its name suggests, this command allows us to obtain information about our computer and the operating system we are using. With the simple fact of executing the command, it will appear by command line information on the computer such as system name, processor, RAM, motherboard, available storage, BIOS, network card, etc.
We probably needed to know the exact version of our Windows operating system that we installed on more than one occasion. Well, the exact version of our system will be shown simply by executing the command see from the command line.
If we write the exit command and press Enter to execute it from the command line, we will see how the CMD or command prompt window closes automatically. And it is that the exit command is the one that we have to use to close the console.
One of the things that some Windows 10 users miss the most is the possibility of opening the control panel quickly and easily. From the command line it is possible to do it very quickly with the simple fact of executing the command control panel, the window of the system control panel will automatically open.
This command is very useful, since it produces an in-depth PC energy-saving chart. By means of this command, all the functions relating to the energy consumption of our equipment, those available in the control panel and other more sophisticated ones are accessible. Very useful especially for laptops because it analyzes the cause of a lower than normal battery and also produces a comprehensive report to check the battery status.
Commands to manage your files and folders from the command prompt
From the command line we can also create new folders and files, delete them or move files from one path to another as we do from the Windows file explorer.
If you want a new directory or folder in the command line path, all you have to do is go into that path and execute the command once:
The only thing we have to do is replace foldername with the name we want to give to the new directory.
If we want to create a path of subfolders within a folder, the command is the same, but instead of indicating the name of the folder, we will have to write the path with the name of the subfolders. For example:
To delete a folder, the first thing we must do is make sure that said directory is empty, since in that case it will not allow us to delete the folder. Once the folder is empty, from the path that contains that folder we will have to execute the command:
Copy is the command that allows us to copy files, that is, copy a file from one directory to another. The command to execute if we want to move file1.ext to the tests folder inside the path where we are, copy file1.ext tests . Now, we can also copy file1.ext to the tests folder but with another name file2.ext, in this case the command to execute is:
copy file1.ext testsfile2.ext
The Copy command can also be used to create a text file inside any CMD folder. All we need to do is type and execute a copy command with filename.txt. As soon as we press Enter to execute a command, the cursor will remain on the line below, and then we can start writing what we want the txt file that we are going to create to contain. To indicate that we’ve finished, press Ctrl + Z and press Enter and we can see how the text file we’ve just created with the text you’ve entered already appears in the specified path.
To copy all the files from one directory or folder to another we are going to use the xcopy command. In this way, we can execute:
xcopy folder1 folder2
We will see how the files in folder1 are copied to folder2. If at the end of the command we add the / S parameter, we will be indicating that directories and sub directories be copied, except those that are empty. If we add the / E parameter, then all of them will be copied, including the empty ones.
The move command allows us, as its name suggests, to move files and folders in CMD. The syntax of this command allows us to move files from one folder to another, including a folder and its contents within another folder. If what we want is to move a file to another folder, we go from the command prompt to the folder where the file that we want to change location is located and execute the move file.ext folder1 command. If the destination is on a different route, then we can use the command as follows:
move file.ext c: destinationpath
Move also allows you to move a file to another location and at the same time rename it, the command this time would be:
move file.ext C: pathnamenewname.ext
FSUTIL FILE CREATENEW
To create other types of files, for example a Word document, from the command prompt, we will use the fsutil file to create new command as follows.
Fsutil file createnew C: pathfilename.ext NNN
Where C: path must be replaced by the path where we want to create said file, filename.ext must indicate its name and extension and NNN the size with which we want to create the Word document or file type.
To delete or delete a file, we are going to use the del command. To do this, we move to the path where this file is located and execute:
The file will automatically be removed from that path.
The ren command allows us to rename both files and folders. In the case that we want to change the name of a file, we will go to the folder that contains it and execute:
ren filename.ext newname.ext
To rename a folder the command would be the same but without specifying the extension:
ren folder1 folder2
Although the dir command mentioned above shows us a list of everything that a folder contains, on many occasions we may want to see the directory tree or directory tree and its contents from the CMD or command prompt. For this, we can use the tree command that if we execute it as it will return the folder tree below the path where we are, but if we execute it as tree / f, it will also show us all the files that each of tree-shaped directories too.
Just as we can easily create a text file from the command line, it is possible to see its contents thanks to the type command. To do this, simply write:
Automatically we will be shown the content of the text file in the console. This command allows you to pass two parameters, that is, two text files, so we can see the content of two files by executing a single command:
type file1.txt file2.txt
Although you need to be very careful when using this command, it should be mentioned to avoid problems. This is a command that allows you to format a drive from the command line on our hard drive. Its syntax is very simple, as you can see below.
How to create, enable and disable Windows users from the CMD
The fact of sharing the computer with other people, makes it necessary to create new user accounts. This is something that Windows itself allows us to do from the system configuration, but we can also manage our user accounts from the command prompt or CMD.
Net user is the command that will facilitate the task of creating a user account in the system. Its syntax is very simple, but we can always consult it by running net user / ?. Either way, to create a new user account we will have to run:
net user User Password / add
Where User and Password we must replace it with the username that we want to create and the password to use.
This same command also allows us to enable or disable a user account, for this we will use the command as follows:
net user User / active: no or net user User / active: yes
Basic network commands
From the command line, it is also possible to access some network resources such as our IP address, DNS addresses or perform some pretty useful tasks at certain times, such as cleaning the DNS cache, among others.
This command allows us to know the status of the network by establishing a communication with a website, for example, and checking if packet delivery is successful. Its use is very simple, just type ping followed by a site, for example Google, and check if the necessary packets are sent and received to establish communication and navigate. Example:
Ipconfig is the command that allows us to know the current TCP / IP network configuration values, such as the name of the adapter or network card used in the connection, the IP address assigned to the equipment, the IP address of the equipment that works as server or proxy and that is the one that has access to the internet, as well as the DNS servers and the DHCP configuration and status. To do this, just go to the command line, type ipconfig and press Enter.
This command also allows us to clear the DNS cache if we use it in the following way, ipconfig / flushdns . Although these are other options that are also used with the ipconfig command: ipconfig / all to show our network card information, ipconfig / release releases the adapter’s IP address and ipconfig / renew, renews the IP address of the network adapter.
This simple command let ‘s know our computer’s MAC address. Note that a computer’s Mac address is a unique identifier that is assigned to a network card or network unit by the manufacturer. Also known as a physical address, each device is unique in itself.
This command allows us to know exactly the route of the packets before reaching the destination computer, which makes it easier for us to detect possible routing failures of the packets in the connection. Its syntax is also very simple, all we have to do is type the tracert command followed by the website with which we want to check the route or IP address of the destination computer.
The status of network activity can also be monitored using this command, which allows you to easily see the network behavior and to know the number of active connections on the PC. The syntax of the command is very basic, we can add an option next to the command, the protocol and the time interval the connections are monitored to.
Netstat [option] [-p protocol] [interval]
These would be the options to use:
-a Shows us all the connections and ports listening.
-b Displays the applications and executable files responsible for creating connections on the listening ports.
-e Ethernet Statistics.
-n To display ports and addresses in numerical format.
-o Shows the identity of each process.
-r Show the route table.
-s Show statistics by protocol.
-v If we use it together with -b, it allows us to see sequences of components in charge of creating the connection.
-p Shows the connections by protocols: TCP, UDP, TCPv6, etc.
Interval, there we will indicate every few seconds that the connections are monitored. We can force the process to end with the keyboard shortcut Ctrl + C.
Commands to fix some system errors
Just like we found some bug solvers in the Windows graphical interface, the Microsoft operating system has other command-based tools that allow us to repair or solve certain problems in the system.
They are the initials of Deployment Image Servicing and Management and refer to a tool developed by Microsoft based on the command line that allows us to perform the maintenance and preparation of system images.
The DISM commands allow us to capture and apply Windows images, add or remove images from a .win file or even divide .win files into smaller ones. To carry out an analysis of a Windows image to detect errors or corrupt files we can execute the command:
Dism / Online / Cleanup-Image / ScanHealth
As always, we can see the rest of the options and parameters by running dism / ?. Keep in mind that to use the DISM tool, we will have to open the command prompt or CMD with administrator permissions.
Another interesting command in this regard is SFC, which allows us to search for corrupted system files and if found, it will automatically try to repair or replace them. Its use is very simple, all we have to do is open a command prompt window with administrator permissions and then execute
sfc / scannow
Now, we just have to wait for the process to finish, since it will try to repair any damaged system file automatically.
This time, the chkdsk command helps us detect problems on our computer’s hard drive or storage unit. In this way, by running the tool from the command line we can detect problems on our disk to avoid major errors. Its use is very simple, we only have to write the chkdsk command followed by a space and the drive letter together with: which corresponds to the partition or disk that we want to analyze. The command admits a series of parameters to indicate if we want that, in addition to detecting them, it tries to correct them (/ F), if it finds defective sectors that tries to recover the information (/ R), etc. We can see all of them executing the command chkdsk / ?.
How to shutdown or restart the PC from the console
If we want to turn off the computer from the command prompt or CMD, Shutdown is the command that we must use. In addition, it allows us to indicate if we want the shutdown to be immediate or even if we want it to be done after a specific time. For example, to automatically shut down the PC, just type and run the command:
shutdown / s / p
Where / s indicates that the system should be shutdown and / p to be performed immediately without waiting for the default command time, which is about 30 seconds.
If, on the contrary, we want our PC to shut down within 1 hour, then we must execute the command:
shutdown / s / t 3600
Where 3600 are the seconds it will wait to turn off. We can see all the shutdown options by running the command shutdown / ?. If for anything we want to cancel the shutdown of the computer programmed by shutdown, then we will have to execute the command shutdown / a.
To restart the computer, then we will have to use this same command but together with the / r parameter. If we execute the command:
shutdown / r / t 60
Our computer will restart in 60 seconds.
Useful keyboard shortcuts at command prompt
Like almost any self-respecting tool, the CMD or command prompt also allows us to use certain key combinations or keyboard shortcuts to perform certain tasks quickly.
When we are typing a command at the command prompt and we want to delete it, just press the Escape key on our keyboard and it will delete everything automatically without having to go character by character.
Up and down arrow
The keys with the up and down arrows on our keyboard allow us in the CMD to move through the commands executed in the console since we opened it. With the cursor of the up arrow we will move through the commands executed previously and with the down arrow we will return to those executed later.
The F7 key shows us a window with the history of commands used at the command prompt. In this way, we can see them all at once and run any of them again by simply selecting it and pressing Enter.
Ctrl + c
This keyboard shortcut allows us to cancel the running process. If for example we have launched a command that is taking a long time to execute and we want to cancel it, we can do it with Ctrl + c.
F11 activates full screen mode so that the command prompt window becomes bigger and we can work more comfortably. If at some point we want to make it smaller again, just press F11 again.
The F3 key rewrites the last command executed in CMD without us having to retype it.
F1 writes us again the last command executed at the command prompt, but this time it does it character by character with each press of the F1 key.