Are the command line and command line utilities relevant today?
Windows users are accustomed to using programs (applications) with a graphical user interface, in which actions are performed using mouse clicks or keyboard input.
At the same time, even in Windows there are and can be installed many utilities, programs without a graphical interface, with very useful functionality. As a rule, programs without a graphical interface are designed to perform a highly specialized action or function and are designed for professionals.
Programs without a graphical interface are called “command line utilities”, “programs with a command line interface” (CLI).
There is no need to think that command line utilities are some kind of atavism and something outdated. This is very far from the truth! Entire layers of specialized programs in various fields are developed precisely as utilities with a command line interface.
The purpose of this note is to give a general idea to Windows users about how to deal with the command line. If you have downloaded the utility and cannot run it, then this note is for you!
When I click on the exe file, a black window flickers and then disappears
When you try to launch the command line utility by double-clicking, you will most likely encounter the console window flashing for a second, which immediately closes.
Programs with a command line interface are not designed to be launched by double-clicking. Instead, they need to be run, as you might have guessed, on the command line.
Windows has several environments for executing commands:
PowerShell (includes all the features of CMD and provides many cmdlets for administering Windows desktops and servers)
You can also remember Windows Terminal, but this is not a separate environment that has its own commands, but just an application for conveniently entering CMD and PowerShell commands.
To run the program, you need to open a Windows Terminal window (or PowerShell). To do this, press the key combination Win+x, and select “Windows Terminal” or “Windows Terminal (Admin)”:
What to choose: “Windows Terminal” or “Windows Terminal (Admin)”
Utilities can be run with normal user rights, or require running with Administrator rights.
With Administrator rights, for example, the following programs should be launched:
Programs that register and install themselves as system services
Programs that require low-level access to devices (for example, programs for partitioning or fixing disk errors)
Programs that change system settings that only an administrator can change.
An example of programs with a command line interface that require Administrator rights:
Apache (web server, it registers and starts itself as a system service)
MySQL (DBMS, it registers and starts itself as a system service)
An example of utilities that do not require elevated privileges:
How to run an executable on the command line
Consider running a program with a command line interface using the Apache web server (httpd) as an example.
The first option: you can simply drag and drop the executable file into the command line window. The Apache executable is httpd.exe.
The second option: on the command line, you can change the current working directory to the one where the Apache executable files are located. For example, my program is located in the C:\Apache24\bin\ folder, to change the current working folder, the “cd” command is used, after which the folder you want to go to is indicated, in my case the command looks like this:
As you can see from the screenshot, the C:\Users\MiAl folder has been changed to C:\Apache24\bin\.
Now, to run the program, it is enough to type the name of the executable file indicating the current folder. The current folder is indicated by a dot (.), then you need to put a backslash, it turns out like this:
Apache is a network service, that is, a program that uses a computer network for its work. Specifically, Apache listens for incoming connections on port 80 (the service opens a port). For this reason, the Windows Firewall asks whether to allow the Apache HTTP Server program to communicate on the network, select “Allow access”.
Already at this stage, the web server is running, and you can open the address http://localhost/ in a web browser
To stop the service, press Ctrl+c.
How to get help using the utility
Typically, command-line utilities support various options that can be specified with a space after the executable file name.
Also, utilities usually have built-in help on available options, which can be displayed using the -h option or the --help option, which must be specified after the executable file name.
In addition to command line options, many services are configured using configuration files, which are text files with a specific syntax. This is especially common for utilities that came to Windows from Linux, since in this operating system many programs are configured using text files.
In this case, quite often explanations of custom directives are contained in the configuration file itself in the form of notes, or in accompanying documentation.
README, ReadMe.txt, README.md files and software documentation
Utilities are usually accompanied by documentation. For example, this is an Apache archive:
As you can see, the ReadMe.txt file with documentation is attached to the archive – this is documentation from those who compiled Apache for Windows.
Inside the Apache24 folder there are even more files and folders with installation information and more.
This is a PHP archive – it also contains a README.md file that provides help information.
A MySQL archive containing a README file and a documentation folder or a link to the documentation.
Program in PATH environment variable
The above shows that in order to run the program, you need to go to the folder with this program.
Alternatively, you can specify the full path to the executable, for example:
It is this method that works when you drag and drop the utility into the console to run the utility – in this case, the full path to the file is inserted into the command line.
But some commands run from any folder, wherever you are on the command line. For example, try the following command:
The fact is that for operating systems there is such a thing as the PATH environment variable.
The essence of the PATH environment variable is as follows:
1. The PATH variable is assigned a value that consists of a list of folders, that is, paths in the system.
2. When you run a file on the command line, the operating system tries to find it both in the current folder (where you went with the “cd” command, or open by default), and in each folder specified in the PATH environment variable
3. If the file is found in the current folder, or in any PATH folder, then it is launched.
This is the reason the following command always works:
The reason is that it is placed in one of the folders listed in PATH (namely C:\Windows\System32\).
To view the current value of the PATH environment variable, run any of the following commands:
Get-ChildItem -Path Env:PATH
Example PATH content in Windows 11:
C:\Program Files\PowerShell\7-preview;C:\Program Files\ImageMagick-7.1.0-Q16-HDRI;C:\Server\bin\PHP\;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\libnvvp;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\NVIDIA Corporation\Nsight Compute 2022.1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\PowerShell\7-preview\preview;C:\Users\MiAl\AppData\Local\Microsoft\WindowsApps
You can place frequently used utilities in a folder included in PATH. Either you can add a new folder to PATH with the utilities you want to run without specifying the full paths to the executable files, or without having to change to the directory with these utilities.
You can set the value of PATH (and other environment variables) both in the GUI and on the command line.
Do I need to specify the extension of the executable file
When running executable files, it is not necessary to specify the extension, because the console will understand what you mean. For example, the following two commands are identical:
This note is intended to give you a general idea of how to start and use the command line utilities. For basic information on using a particular utility, see the help displayed with the -h option or the program's documentation.
If you encounter an error when starting the utility, try running the program in an elevated command prompt (with admin rights).
If you get a message that “file not found”, go to the folder with the installed program using the “cd” command, or drag and drop the executable file to the command line.
If you received an error message inside the program when starting the program, then study the utility options and examples of its launch in more detail.