What Is a Command-Line Interface?

A command-line interface (CLI) allows you to navigate, run programs or configure your computer system by entering text commands. Here’s what makes a CLI distinct from a GUI.

Written by Abdishakur Hassan
Published on Mar. 01, 2023
Image: Shutterstock / Built In
Image: Shutterstock / Built In
Brand Studio Logo

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)

Command-line interface (CLI) image comparing a graphical user interface (GUI) vs. a command-line interface (CLI)
Graphical user interface (GUI) vs command-line interface (CLI) | Image: Abdishakur Hassan

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:

  1. Open the “Start” menu.
  2. Select the power icon at the bottom.
  3. 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

More From Built In’s Tech DictionaryWhat Is JSON?

 

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.

Command-line interface (CLI) screenshot of three different examples of CLI terminals with commands. The CLIs have black backgrounds and white text with orange boxes highlighted as discussed below.
Screenshots of three different examples of CLI examples. | Image: Abdishakur Hassan

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 dircommand 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. 

Keyboards & Command-Line Interfaces: Crash Course Computer Science #22. | Video: CrashCourse

 

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.
Find out who's hiring.
See all Developer + Engineer jobs at top tech companies & startups
View 10000+ Jobs

 

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.

Command-line interface table of CLI commands for Windows and Linux
Helpful CLI commands for Windows and Linux. | Image: Abdishakur Hassan
Explore Job Matches.