Command line is an interface we use to interact with the computer operating system using the keyboard. With a command-line interface, you can enter text commands to navigate, run programs or configure your computer system. All operating systems, including Windows, Linux and macOS, provide a CLI in addition to the graphical user interface (GUI).
In Microsoft Windows, you can use the command prompt and the Powershell application as a command-line interface. Linux and Unix-based operating systems have Bourne-Again Shell (bash) as the default CLI. Microsoft has recently added the Windows Subsystem for Linux, which enables Windows users to use Linux bash.
CLI vs. GUI: What’s the Difference?
A graphical user interface (GUI) allows users to interact with the operating system by clicking menus, buttons and icons. This is how most users interact with operating systems (and likely how you navigated to this article). For example, to restart your computer using Windows 10/11:
- Open the “Start” menu.
- Select the power icon at the bottom.
- Click “Restart.”
You can perform the same operation using CLI. On a command prompt, enter the following command and your computer will restart.
shutdown /r
How Do Command Line Interfaces Work?
The command-line interface (CLI) accepts commands by entering text on a keyboard. Different CLIs have different syntaxes, but they can all essentially perform the same operations.
Once you run the command, the computer interprets the command and executes the appropriate actions. The CLI also provides feedback to the user, such as error messages or output from the commands. To illustrate how it works, let’s look at a simple example.
The first example calls the time command on the terminal, and the CLI gives an output of the current time with this message:
The current time is: 14:24:40.94.
Enter the new time:
The second example gives the computer a command to create a directory/folder called cli using the command mkdir cli
.
The third example runs the dir
command to display a list of a folder’s files and subfolders. You’ll notice that the cli directory we’ve created is included in this list.
Benefits of Using a CLI
There are several advantages to using a command-line interface (CLI). The most notable are:
- Speed: CLI enables you to execute commands quickly. You can combine multiple commands into a single line of text to run your program. This is much faster than navigating through menus with a GUI.
- Resources: CLI requires fewer computing resources to execute commands than a graphical interface.
- Repetitive Tasks: CLI is effective in automating repetitive tasks and ou can create a batch file to automate tasks at any given time.
- Power-user: A CLI is ideal for power users because it provides access to commands that are unavailable in a GUI. For example, certain tasks are system protected and cannot be accessed through a GUI.
Useful CLI Commands
Windows and Linux CLIs have slightly different syntaxes. Here are some useful commands in both Windows (PowerShell and a command prompt) and Linux.