Command Line Interface
CLI
- In Turkish
- Komut Satırı Arayüzü
- Pronunciation
- see-el-EYE
In short
A command line interface (CLI) is a text-based way of using a computer: you type a command with options and arguments, press Enter, and read its output.
What is a command line interface?
Instead of clicking through menus, you write what you want: git commit -m "Fix login" or docker run -p 8080:80 nginx. A command has a name, arguments such as file names, and options or flags that change its behavior, written as -v or --verbose. Almost every tool prints its usage with --help.
Developers rely on CLIs because they are fast, precise and scriptable. Anything typed can be saved in a script, repeated in a CI pipeline or combined with other commands through pipes. Tools such as git, npm, docker, kubectl and cloud CLIs are often more capable than their graphical counterparts, and remote servers are usually managed entirely through the command line over SSH.
Well-behaved CLI programs follow shared conventions: they read input from standard input, write results to standard output and errors to standard error, and return an exit code, where 0 means success and anything else means failure. Following these rules is what lets small tools be chained together reliably.
A common misconception is that the command line, the terminal and the shell are the same thing. The terminal is the window that shows text, the shell, such as Bash or PowerShell, interprets what you type, and a CLI is the text interface of a particular program, such as git's.
Key takeaways
- A CLI is a text interface: type a command, read the output.
- Commands take arguments and options such as --verbose.
- CLIs are fast, precise and easy to script and automate.
- Exit code 0 means success; stdout and stderr carry output and errors.
- Terminal, shell and CLI are different layers.
Example
# program subcommand options argument
git commit --amend --no-edit # (no argument)
grep -rin --include="*.ts" "TODO" src/
# Most tools explain themselves
docker run --help
# Exit codes make commands scriptable
npm test && echo "Tests passed" || echo "Tests failed: exit code $?"Readers ask
What is the difference between a CLI and a GUI?
A CLI is operated by typing text commands; a GUI, a graphical user interface, by clicking windows, buttons and menus. CLIs are easier to automate and script, while GUIs are easier to discover for new users.
Why do developers use the command line?
It is faster for many tasks, works the same on remote servers, can be scripted and automated, and many developer tools offer their full functionality only through a CLI.
What is an exit code?
A number a program returns when it finishes. Zero means success and any other value signals an error, which scripts and CI pipelines check to decide what to do next.
See also
- TerminalOperating Systems, p. 32A terminal is the program that shows a text interface, passing your keystrokes to a shell or command-line program and displaying the text it sends back.
- ShellOperating Systems, p. 27A shell is a program that reads commands typed by a user or written in a script and asks the operating system to run them, usually through a text interface.
- BashProgramming Languages, p. 2Bash is a Unix shell and scripting language, the default on most Linux systems, used both to type commands interactively and to automate tasks with scripts.
- PowerShellProgramming Languages, p. 24PowerShell is Microsoft's command-line shell and scripting language for automating administration, passing objects rather than plain text between commands.
- SSHNetworking, p. 28SSH is a cryptographic network protocol for securely logging in to and running commands on remote computers, encrypting all traffic between the two machines.
- LinuxDevOps & Cloud, p. 33Linux is an open-source operating system kernel that powers most servers, cloud platforms, containers, and Android phones, usually packaged as a distribution.
Spotted a mistake or something missing on this page?Suggest an edit