What is a command-line interface (CLI)? (2024)

By

  • Peter Loshin,Former Senior Technology Editor
  • Alexander S. Gillis,Technical Writer and Editor

What is a command-line interface?

A command-line interface (CLI) is a text-based user interface (UI) used to run programs, manage computer files and interact with the computer. Command-line interfaces are also called command-line user interfaces, console user interfaces and character user interfaces. CLIs accept as input commands that are entered by keyboard; the commands invoked at the command prompt are then run by the computer.

Today, most vendors offer the graphical user interface (GUI) as the default for operating systems (OSes) such as Windows, Linux and macOS. Most current Unix-based systems offer both a command-line interface and a graphical user interface.

The MS-DOS operating system and the command shell in the Windows operating system are examples of command-line interfaces. In addition, programming language development platforms such as Python can support command-line interfaces.

The command line dropped in popularity following the introduction of GUI-based personal computer OSes like Microsoft Windows and Apple's "classic" Mac OS in the 1980s. The command line remains an important tool for IT professionals, software developers, sys admins, network administrators and many others who prefer a more precise and reproduceable interface to their systems.

What is a shell?

In computing, a shell program provides access to an operating system's components. The shell gives users (or other programs) a way to get "inside" the system to run programs or manage configurations. The shell defines the boundary between inside and outside.

The following are the two types of operating system shells:

  • CLI-based shells offer users a concise and efficient mode of interacting with the OS, without requiring the overhead of a graphical user interface.
  • GUI-based shells are considered easier for beginners to use, but they also include a CLI-based shell for system administrators or power users who prefer to interact at a command prompt.

Bash is the most commonly used command-line shell for Unix-based OSes including Linux.

The software that handles the command-line interface is commonly referred to as a command language interpreter, a command processor or command interpreter. Two well-known CLI shells are PowerShell for Windows and Bash for Linux and macOS.

Shells are the outermost layer of the OS and are often separated from the underlying OS kernel. A shell operates like an application and can be replaced as needed. An OS may have more than one shell available, as in the following examples:

  • Microsoft Windows includes the Command Prompt app as well as the PowerShell application, both of which can be used to interact directly with the computer. The Windows Subsystem for Linux also provides a CLI with access to the underlying system.
  • Linux and other Unix-based operating systems usually provide the Bourne-Again Shell (bash) as the default shell. Other shells, including the C shell, Z shell and others, can be configured as the default system shell.

Because the shell is only one layer above the OS, users can perform operations that are not available in other interface types, such as moving files within system folders and deleting locked files.

To get the greatest benefit from using a CLI shell, users should learn a scripting language. Most command line shells can save sequences of commands in a script or batch file which may be fully programmable. Shell scripting is the foundation of basic systems management automation.

How do CLIs work?

Once a computer system is running, its CLI opens on a blank screen with a command prompt and commands can be entered.

Types of CLI commands include the following:

  • system commands that are encoded as part of the operating system interface;
  • executable programs that, when successfully invoked, run text-based or graphical applications; and
  • batch programs (or batch files or shell scripts) which are text files listing a sequence of commands. When successfully invoked, a batch program runs its commands which may include both system commands and executable programs.

CLI is more than a simple command/response system, as most have additional features that make one preferable to another. Some features include the following:

  • Scripting capability enables users to write programs that can be run on the system from the command line.
  • Command pipes enable users to direct the output of one program to be the input for another program ("piping" the flow of data).
  • System variables can be set at the command line, or the values of those variables displayed.
  • Command history features enable the user to recall previous commands issued. Some save command history for the session (like PowerShell), others can be configured to store session history for longer (like bash).

Commands and syntax for CLIs tend to be very stable over time, in part to enable backward compatibility for scripts.

Prompts and commands

Depending on the operating system and the CLI, there may be hundreds or even thousands of different executable commands available. The set of commands may vary dramatically between operating systems or applications.

For example, Microsoft defines hundreds of cmdlets as "lightweight commands" to be used in PowerShell; PowerShell functions are lists of cmdlets that can be run at the command line.

Some commands run at the command line by themselves, such as the dir command:

C:\> dir

Commands can also be used with arguments (sometimes referred to as parameters) that modify how the command should be run. Arguments follow the command and provide additional details or specifics.

The cd "change directory" command in many CLIs is used to change the current working directory when the desired new directory path is included as an argument -- but in some cases (as in MS-DOS or the Windows command prompt) the command by itself returns the current working directory.

This command resets the current working directory:

cd \documents\user\working

Arguments enable command-line users to get very specific results that are sometimes not available through a graphical interface.

Modern CLIs provide pipes, or mechanisms for taking the output of one command and sending it as input to another command. The vertical bar, or "|" symbol, is often used for this purpose.

The following "one-liner" uses pipes to string together several PowerShell commands to retrieve detailed network configuration information from a Windows machine:

Get-NetIPAddress | Sort InterfaceIndex | FT InterfaceIndex, InterfaceAlias, AddressFamily, IPAddress

Even though this string is entered at the command line as if it were a single command, it includes the following consecutive commands:

  • Get-NetIPAddress retrieves all IP configuration information for the computer when entered without any arguments.
  • Sort InterfaceIndex accepts as input the output of the Get-NetIPAddress cmdlet and sorts it by the InterfaceIndex value associated with each IP address included in the computer configuration.
  • FT InterfaceIndex, InterfaceAlias, AddressFamily, IPAddress uses the Format-Table (FT) command to format the sorted output of the previous command and displays the specified values for each IP address.

Backward compatibility is often a goal when new CLIs are introduced to replace existing CLIs, as when Microsoft replaced MS-DOS with the Windows Command Prompt. Though some MS-DOS commands are no longer supported, most will still work in PowerShell as originally intended.

Common MS-DOS commands include the following:

CommandExampleNotes
CDC:\> CD \user\programs
C:\user\programs>
Changes the current directory to the specified path. When entered with no path, it displays the current working directory's name. If the path is included in the command prompt, the prompt will change as in the example (see also PROMPT, below).
CHKDSKC:\> CHKDSK a:Checks the specified disk -- in this case, the floppy disk in the A: drive -- and returns a status report showing the disk size, number of files and directories in use and number of bytes used.
COPYC:\> COPY autoexec.bat autoexec.BAKCopies specified file or files. Can be used to copy files to duplicates with different file names or to copy files into a different directory without changing names.
DELC:\> DEL autoexec.BAK
C:\> DEL C:\backups\*.BAK
Deletes a file or files. Can be used to delete files in the current working directory or in some other directory. Can also be used with wildcard characters to delete groups of files.
DIRC:\> DIR
C:\> DIR c:\backups\*.txt
Displays all contents -- files and directories -- in the specified directory. If no directory is specified, it refers to the contents of the current directory. It can also be used with wildcard characters to display only specific files.
EDLINC:\> edlin autoexec.batStarts edlin, a line editor that can be used to edit text files. In this example, it is being used to edit the autoexec.bat file.
FORMATC:\> FORMAT a:Formats a disk so it can be used with MS-DOS.
MKDIRC:\> MKDIR c:\NewDIRCreates a new directory in the specified path.
MOREC:\> MORE autoexec.batDisplays contents of a file, one screen at a time. It is mostly used for text files.
PROMPTC:\> prompt $p $d$g
C:\UTIL Fri 11-05-2021>
Modifies the default prompt. In this example, parameters are used with the command to set the prompt display as the current drive and path, the day and date and the greater-than symbol. The resulting prompt is shown in the example.
RMDIRC:\> rmdir c:\backupRemoves a directory.
TYPEC:\> type autoexec.batDisplays content of a text file, without page breaks.

CLI versus GUI

The graphical user interface is the most popular user interface today. A GUI uses windows, menus and icons to execute commands. Using a mouse is the most common way to navigate through a GUI, although many GUIs allow some navigation and program execution via a keyboard.

Microsoft Word is an example of a GUI-based application. A user can change options for page layouts and styles by selecting the corresponding icon or pull-down menu with a mouse or keyboard.

What is a command-line interface (CLI)? (1)

One advantage of a GUI is the interface can visually display available functions. However, because it relies on graphical display, a GUI may not have the same level of functionality and granular control as a command-line interface. For example, it can require numerous clicks and movement through several dialog boxes in a GUI to accomplish the same result as a single command line.

In addition, GUIs do not readily support scripting or automation. For common tasks, a user must repeat each click or navigate each dialog within the GUI manually.

System administrators who may need to manage hundreds -- or hundreds of thousands -- of systems and configurations will find a GUI far less efficient than a CLI. A simple CLI command can easily adjust configurations for a large group of systems at once.

Commands and arguments can also be combined and saved, then executed as a script each time that specific action -- or comprehensive set of actions -- is required. The CLI is the preferred tool for many enterprise-wide systems management tasks.

What is a command-line interface (CLI)? (2)

CLI advantages and disadvantages

The following are advantages of a command-line interface:

  • granular control of an OS or application;
  • more efficient management of a large number of systems;
  • ability to store scripts to automate regular tasks; and
  • basic command-line interface knowledge can enable troubleshooting of network connection issues or resolving other system tasks.

The disadvantages of a command-line interface are the following:

  • GUI is more user friendly;
  • steeper learning curve associated with memorizing commands and complex syntax/arguments; and
  • different commands used in different shells.

The command line is a great place to become an expert at using a computer. Once you're ready, it's also the only place to learn how to write shell scripts.

This was last updated in December 2021

Continue Reading About command-line interface (CLI)

  • These IT automation scripts take little effort and save a lot of work
  • When and how to use the AWS Command Line Interface
  • PowerShell vs. Bash: Key differences for Windows deployments
  • Advanced shell scripting for IT ops professionals: Free chapter
  • Work a command-line interface in Linux with these permissions and prompts

Related Terms

What is an uninterruptible power supply (UPS)?
An uninterruptible power supply (UPS) is a device that allows a computer to keep running for at least a short time when incoming ...Seecompletedefinition
What is Microsoft Azure File Service?
Microsoft Azure Files -- sometimes known as Microsoft Azure File Service -- is a simple, secure, serverless, fully managed and ...Seecompletedefinition
What is the blue screen of death (BSOD)?
The blue screen of death (BSOD) -- also known as a stop error screen, blue screen error, fatal error or bugcheck -- is a critical...Seecompletedefinition

Dig Deeper on IT operations and infrastructure management

  • 8 network tasks administrators can do quicker from the CLIBy: DamonGarn
  • shell programBy: RobertSheldon
  • How to interact with network APIs using cURL, Postman toolsBy: VerlaineMuhungu
  • What are the advantages and disadvantages of CLI and GUI?By: AndrewFroehlich
What is a command-line interface (CLI)? (2024)

FAQs

What is CLI or command-line interface? ›

A command line interface (CLI) is a text-based interface where you can input commands that interact with a computer's operating system. The CLI operates with the help of the default shell, which is between the operating system and the user.

What is a command-line interface CLI quizlet? ›

Command line interface works like a messenger conversation with your computer. The computer tells you it's ready to receive commands by displaying a specific set of characters called a PROMPT.

What do you mean by command-line interface? ›

A command-line interface (CLI) is a text-based user interface (UI) used to run programs, manage computer files and interact with the computer. Command-line interfaces are also called command-line user interfaces, console user interfaces and character user interfaces.

Is Command Prompt a CLI? ›

One of the terms you'll hear quite often is the Command Line Interface (also referred to as Command Prompt or Terminal). The Command Line Interface (CLI) is an editing environment that is text-based.

What are 5 examples of command line interfaces? ›

Command Line Interface (CLI) Examples
  • Synchronous Filesystem Operations.
  • Single Item Transfers.
  • Batch Transfers.
  • Deletions.
  • Task Management.
  • Bookmarks.
  • Safe Resubmissions.

Why use CLI? ›

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.

What does the CLI stand for quizlet? ›

The CLI is one of the ways of issuing commands to operating system. CLI stands for: Command Line Interface.

What is the command line interface or command-line interpreter? ›

Operating system (OS) command-line interfaces are usually distinct programs supplied with the operating system. A program that implements such a text interface is often called a command-line interpreter, command processor or shell.

What does the CLI prompt? ›

By default, the CLI command prompt indicates the device being accessed and the current CLI context. For example, the prompt: A:ALA-1>config>router>if# indicates the active context, the user is on the device with hostname ALA-1 in the configure>router>interface context.

What is cmd used for? ›

What is CMD? CMD is an abbreviation of the word “command” and is used when referencing Windows command processor, aka Command Prompt. CMD is a powerful tool for Windows operating systems that allows users to interact with the computer using text-based CMD commands through the command line interface.

What is the most popular command line interface? ›

The three most popular operating systems and their command-line interface names are:
  • Windows: Command Prompt.
  • Linux: Bash (Bourne Again Shell)
  • MacOs: Terminal.
Nov 29, 2023

What is the function of the command line? ›

The command line is a text interface for your computer. It's a program that takes in commands, which it passes on to the computer's operating system to run. From the command line, you can navigate through files and folders on your computer, just as you would with Windows Explorer on Windows or Finder on Mac OS.

What can you do in command line? ›

Out of the box, here are just a few of the things the command line can do, along with the names of relevant tools in each case: Navigate your computer's file system along with base-level tasks such as create, copy, rename, and delete: Move around your directory structure: cd. Create directories: mkdir.

What is a Prompt in command line interface? ›

In Windows operating systems, the Command Prompt is a program that emulates the input field in a text-based user interface screen with the Windows Graphical User Interface (UI). It can be used to perform entered commands and perform advanced administrative functions.

How to write commands in CLI? ›

List of CLI commands
  1. ls - List directory contents. ls -a - List all the content, including hidden files. ls -l - List the content and its information.
  2. cd foldername – Change the working directory to foldername. cd - Return to $HOME directory. ...
  3. cat file – Print contents of file on the screen. less file - View and paginate file.

How do I open the command line interface? ›

Opening: Windows

Go to Start menu → Windows System → Command Prompt. Go to Start menu → All Programs → Accessories → Command Prompt. Go to the Start screen, hover your mouse in the lower-left corner of the screen, and click the down arrow that appears (on a touch screen, instead flick up from the bottom of the screen).

What is the difference between GUI and CLI interface? ›

GUI lets a user interact with the device/system with the help of graphical elements, like windows, menus, icons, etc. The CLI, on the other hand, lets a user interact with their device/system with the help of various commands. Some OS provide their users with only CLI, while some offer both CLI and GUI.

Does Windows use command line interface? ›

Windows has two command-line shells: the Command shell and PowerShell. Each shell is a software program that provides direct communication between you and the operating system or application, providing an environment to automate IT operations.

What is the command line interface in Windows known as? ›

Command prompt and Powershell are the two CLI used in Windows OS.

Top Articles
How Do I Redeem My American Express Rewards?
automated sniping
Kevin Cox Picks
122242843 Routing Number BANK OF THE WEST CA - Wise
Jeremy Corbell Twitter
Craigslist Furniture Bedroom Set
Www Craigslist Louisville
Achivr Visb Verizon
Hover Racer Drive Watchdocumentaries
Midlife Crisis F95Zone
10-Day Weather Forecast for Florence, AL - The Weather Channel | weather.com
[Birthday Column] Celebrating Sarada's Birthday on 3/31! Looking Back on the Successor to the Uchiha Legacy Who Dreams of Becoming Hokage! | NARUTO OFFICIAL SITE (NARUTO & BORUTO)
Les Rainwater Auto Sales
Destiny 2 Salvage Activity (How to Complete, Rewards & Mission)
Committees Of Correspondence | Encyclopedia.com
Salem Oregon Costco Gas Prices
Invert Clipping Mask Illustrator
Honda cb750 cbx z1 Kawasaki kz900 h2 kz 900 Harley Davidson BMW Indian - wanted - by dealer - sale - craigslist
3S Bivy Cover 2D Gen
Craigslist Sparta Nj
Ivegore Machete Mutolation
All Obituaries | Gateway-Forest Lawn Funeral Home | Lake City FL funeral home and cremation Lake City FL funeral home and cremation
8005607994
Low Tide In Twilight Ch 52
Essence Healthcare Otc 2023 Catalog
Apparent assassination attempt | Suspect never had Trump in sight, did not get off shot: Officials
Marquette Gas Prices
Telegram Voyeur
Ascensionpress Com Login
Roseann Marie Messina · 15800 Detroit Ave, Suite D, Lakewood, OH 44107-3748 · Lay Midwife
Landing Page Winn Dixie
Nacogdoches, Texas: Step Back in Time in Texas' Oldest Town
Max 80 Orl
A Small Traveling Suitcase Figgerits
De beste uitvaartdiensten die goede rituele diensten aanbieden voor de laatste rituelen
Lichen - 1.17.0 - Gemsbok! Antler Windchimes! Shoji Screens!
Pill 44615 Orange
Spinning Gold Showtimes Near Emagine Birch Run
Sams La Habra Gas Price
Michael Jordan: A timeline of the NBA legend
Does Target Have Slime Lickers
Noh Buddy
M&T Bank
Sea Guini Dress Code
Dancing Bear - House Party! ID ? Brunette in hardcore action
18 Seriously Good Camping Meals (healthy, easy, minimal prep! )
Quest Diagnostics Mt Morris Appointment
Pelican Denville Nj
Deshuesadero El Pulpo
Wwba Baseball
Optimal Perks Rs3
Dinargurus
Latest Posts
Article information

Author: Golda Nolan II

Last Updated:

Views: 6069

Rating: 4.8 / 5 (58 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Golda Nolan II

Birthday: 1998-05-14

Address: Suite 369 9754 Roberts Pines, West Benitaburgh, NM 69180-7958

Phone: +522993866487

Job: Sales Executive

Hobby: Worldbuilding, Shopping, Quilting, Cooking, Homebrewing, Leather crafting, Pet

Introduction: My name is Golda Nolan II, I am a thoughtful, clever, cute, jolly, brave, powerful, splendid person who loves writing and wants to share my knowledge and understanding with you.