Bookmarks

CLI — command-line interface

A way for a person to communicate with a program through text: the user types commands, and the program replies with lines of text and returns an exit code.

Also: command line, console, CLI

checked 9 Nov

All terms

In a CLI the user types a command, a program name plus arguments, and gets a text response. This is how git, docker, ssh and Linux utilities such as grep and curl work. A text interface is easy to automate: the same commands go into scripts and CI unchanged.

What a command consists of

A typical command consists of a program name, arguments and options:

bash
docker run --rm -p 8080:80 nginx:latest
  • The name says which program to call: docker.
  • Positional arguments say what to work on: run, nginx:latest.
  • Options (flags) say how to work: --rm removes the container after it stops, -p 8080:80 publishes a port.

POSIX defines a command as a directive to the shell to perform a task, an argument as a parameter passed to a utility, and an option as an argument that changes its default behaviour. The shell (bash, zsh, PowerShell) prints a prompt, reads a line, parses it and runs the program; the output goes back to the screen.

Why the CLI lives on in automation

A program with a CLI returns an exit code: 0 means success, non-zero means an error. Commands are joined in a pipeline, where the output of one becomes the input of the next:

bash
grep ERROR app.log | wc -l

That is why the CLI is the main interface for headless servers, scripts and CI/CD pipelines: whatever a person types by hand, a script repeats in the same way.

GUI and TUI

A GUI shows buttons and windows and is designed for the mouse; a CLI is designed for the keyboard and text. A TUI fills the whole terminal with windows and menus, as in htop, but remains text.

Sources

the term is written from these pages

Verified 9 Nov

Not to be confused with

what it is mixed up with and how it differs

In depth in the references

where the topic is covered in detail