All Topics  
Command line interface

 

   Email Print
   Bookmark   Link






 

Command line interface



 
 
A command-line interface (CLI) is a mechanism for interacting with a computer operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
 or software by typing commands to perform specific tasks.






Discussion
Ask a question about 'Command line interface'
Start a new discussion about 'Command line interface'
Answer questions from other users
Full Discussion Forum



Encyclopedia


Bash Screenshot
Aux
A command-line interface (CLI) is a mechanism for interacting with a computer operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
 or software by typing commands to perform specific tasks. This text-only interface contrasts with the use of a mouse pointer
Mouse (computing)

In computing, a mouse is a pointing device that functions by detecting dimension motion relative to its supporting surface. Physically, a mouse consists of an object held under one of the user's hands, with one or more buttons....
 with a graphical user interface
Graphical user interface

A graphical user interface is a type of user interface which allows people to human-computer interaction such as computers; hand-held devices such as MP3 Players, Portable Media Players or Gaming devices; household appliances and office equipment....
 (GUI) to click on options, or menus on a text user interface
Text user interface

TUI short for: Text User Interface or Textual User Interface , is a retronym that was coined sometime after the invention of graphical user interfaces, to distinguish them from Text-based user interfaces....
 (TUI) to select options.

This method of instructing a computer to perform a given task is referred to as "entering" a command: the system waits for the user to conclude the submitting of the text command by pressing the "Enter" key (a descendant of the "carriage return" key of a typewriter keyboard). A command-line interpreter then receives, analyses
Parsing

In computer science and linguistics, parsing, or, more formally, syntactic analysis, is the process of analyzing a sequence of lexical analysis#Token to determine their grammatical structure with respect to a given formal grammar....
, and executes the requested command. The command-line interpreter may be run in a text terminal
Computer terminal

A computer terminal is an electronic or electromechanical computer hardware device that is used for entering data into, and displaying data from, a computer or a computing system....
 or in a terminal emulator
Terminal emulator

A terminal emulator, terminal application, term, or tty for short, is a program that emulates a "dumb" video Computer terminal within some other display architecture....
 window as a remote shell client such as PuTTY
PuTTY

PuTTY is a terminal emulator application which can act as a client for the Secure Shell, Telnet, rlogin, and Transmission Control Protocol computing protocols....
. Upon completion, the command usually returns output to the user in the form of text lines on the CLI. This output may be an answer if the command was a question, or otherwise a summary of the operation.

The concept of the CLI originated when teletype
Teleprinter

A teleprinter is a now largely obsolete electro-mechanical typewriter which can be used to communicate typed messages from Point-to-point and Point-to-multipoint communication over a variety of communications channels that range from a simple electrical connection, such as a pair of wires, to the use of radio and microwave as the transmi...
 machines (TTY) were connected to computers in the 1950s, and offered results on demand, compared to 'batch' oriented mechanical punch card
Punch card

A punch card or punched card , is a piece of paperboard that contains digital information represented by the presence or absence of holes in predefined positions....
 input technology. Dedicated text-based CRT
Cathode ray tube

The cathode ray tube is a vacuum tube containing an electron gun and a fluorescent screen, with internal or external means to accelerate and deflect the electron beam, used to create images in the form of light emitted from the fluorescent screen....
 terminals followed, with faster interaction and more information visible at one time, then graphical terminals
Computer terminal

A computer terminal is an electronic or electromechanical computer hardware device that is used for entering data into, and displaying data from, a computer or a computing system....
 enriched the visual display of information. Currently personal computers encapsulate both functions in software.

The CLI continues to co-evolve with GUIs like those provided by Microsoft Windows
Microsoft Windows

Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces ....
, Mac OS
Mac OS

Mac OS is the trademarked name for a series of graphical user interface-based operating systems developed by Apple Inc. for their Macintosh line of computer systems....
 and the X Window System
X Window System

The X Window System is a computing software system and network protocol that provides a graphical user interface for networked computers. It implements the X Window System protocols and architecture and provides windowing system on raster graphics Visual display units and manages Keyboard and pointing device control functions....
. In some applications, such as MATLAB
MATLAB

MATLAB is a Numerical analysis environment and programming language. Maintained by The MathWorks, MATLAB allows easy matrix manipulation, plotting of function and data, implementation of algorithms, creation of user interfaces, and interfacing with programs in other languages....
 and AutoCAD, a CLI is integrated with the GUI, with the benefits of both.

Usage


A CLI is used whenever a large vocabulary of commands or queries, coupled with a wide (or arbitrary) range of options, can be entered more rapidly as text than with a pure GUI. This is typically the case with operating system command shell
Shell (computing)

In computing, a shell is a piece of software that provides an Interface for users. Typically, the term refers to an operating system shell which provides access to the services of a kernel ....
s. Also, some computer languages (such as Python
Python (programming language)

Python is a general-purpose high-level programming language. Its design philosophy emphasizes code readability. Python's core syntax and semantics are Minimalism , while the standard library is large and comprehensive....
, Forth, LISP
Lisp

A lisp is a speech impediment, historically also known as sigmatism. Stereotypically, people with a lisp are unable to pronounce sibilants , and replace them with Interdental consonants , though there are actually several kinds of lisps....
 and many dialects of BASIC
BASIC

In computer programming, BASIC is a family of high-level programming languages. The Dartmouth BASIC was designed in 1964 by John George Kemeny and Thomas Eugene Kurtz at Dartmouth College in New Hampshire, United States to provide computer access to non-science students....
) provide an interactive command line mode to allow for experimentation.

CLIs are often used by programmers and system administrators, in engineering and scientific environments, and by technically advanced personal computer users. CLIs are also popular among people with visual disability, since the commands and feedbacks can be displayed using Refreshable Braille display
Refreshable Braille display

A refreshable Braille display or Braille terminal is an electro-mechanical device for displaying Braille characters, usually by means of raising dots through holes in a flat surface....
s.

A program that implements such a text interface is often called a command-line interpreter or shell
Shell (computing)

In computing, a shell is a piece of software that provides an Interface for users. Typically, the term refers to an operating system shell which provides access to the services of a kernel ....
. Examples include the various Unix shell
Unix shell

A Unix shell is a command-line interpreter and script host that provides a traditional user interface for the Unix operating system and for Unix-like systems....
s (sh, ksh, csh, tcsh, bash, etc.), the historical CP/M
CP/M

CP/M is an operating system originally created for Intel 8080/Intel 8085 based microcomputers by Gary Kildall of Digital Research. Initially confined to single tasking on 8-bit processors and no more than 64 kilobytes of memory, later versions of CP/M added multi-user variations, and were migrated to 16-bit processors....
, and MS-DOS/IBM-DOS
DOS

DOS, short for "Disk Operating System", is a shorthand term for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions Windows 95, Windows 98, and Windows Me....
's COMMAND.COM
COMMAND.COM

COMMAND.COM is the filename of the default operating system Shell for DOS operating systems and the default command line interpreter on 16/32-bit versions of Microsoft Windows ....
, the latter two based heavily on DEC's
Digital Equipment Corporation

Digital Equipment Corporation was a pioneering United States company in the computer industry. It is often referred to within the computing industry as DEC ....
 RSX
RSX-11

RSX-11 is a family of real-time operating systems mainly for PDP-11 computers created by Digital Equipment Corporation , common in the late 1970s and early 1980s....
 and RSTS
RSTS/E

RSTS is a multi-user time-sharing operating system, developed by Digital Equipment Corporation , for the PDP-11 series of 16-bit minicomputers....
 CLIs. (DOS, i.e. MS-DOS/IBM-DOS, is actually is based on CP/M, DOS having been originally written as a substitute for CP/M-86 when its release was delayed.)

In November 2006, Microsoft
Microsoft

Microsoft Corporation is a multinational corporation computer technology corporation that develops, manufactures, licenses, and supports a wide range of computer software products for computing devices....
 released version 1.0 of Windows PowerShell
Windows PowerShell

Windows PowerShell is an extensible command line interface shell and associated scripting language from Microsoft. It was released in 2006 and is currently available for Windows XP SP2/SP3, Windows Server 2003, Windows Vista and is included in Windows Server 2008 as well as Windows 7 as an optional feature....
 (formerly codenamed Monad), which combined features of traditional Unix shells with their object-oriented .NET Framework
.NET Framework

The Microsoft .NET Framework is a software framework that is available with several Microsoft Windows operating systems. It includes a large Library of coded solutions to prevent common programming problems and a virtual machine that manages the execution of programs written specifically for the Software framework....
. MinGW
MinGW

MinGW , formerly mingw32, is a native porting of the GNU Compiler Collection to Microsoft Windows, along with a set of freely distributable import libraries and header files for the Windows API....
 and Cygwin
Cygwin

Cygwin is a Unix-like environment and command-line interface for Microsoft Windows. Cygwin provides native integration of Windows-based applications, data, and other system resources with applications, software tools, and data of the Unix-like environment....
 are open source
Open source

Open source is an approach to design, development, and distribution offering practical accessibility to a product's source . Some consider open source as one of various possible design approaches, while others consider it a critical Strategy element of their business operations....
 packages for Windows that offer a Unix like CLI. Microsoft provides MKS Inc.'s ksh
Korn shell

The Korn shell is a Unix shell which was developed by David Korn in the early 1980s. It is backwards-compatible with the Bourne shell and includes many features of the C shell as well, such as a command history, which was inspired by the requests of Bell Labs users....
 implementation MKS Korn shell for Windows through their Services for UNIX
Microsoft Windows Services for UNIX

Microsoft Windows Services for UNIX is a software package produced by Microsoft which provides a Unix subsystem and other parts of a full Unix environment on Windows NT and its successors....
 add-on.

The latest versions of the Macintosh
Macintosh

File:Imac alu.pngMacintosh, commonly shortened to Mac, is a brand name which covers several lines of personal computers designed, developed, and marketed by Apple Inc....
 operating system are based on a variation of Unix called Darwin
Darwin (operating system)

Darwin is an open source POSIX-compliant computer operating system released by Apple Inc. in 2000. It is composed of code developed by Apple, as well as code derived from NEXTSTEP, FreeBSD, and other free software projects....
. On these computers, users can access a Unix-like command-line interface called Terminal found in the Applications Utilities folder. (This terminal uses bash
Bash

Bash is a free software Unix shell written for the GNU Project. Its name is an acronym which stands for Bourne-again shell. The name is a pun on the name of the Bourne shell , an early and important Unix shell written by Stephen Bourne and distributed with Version 7 Unix circa 1978, and the concept of being "Born again Christianity"....
 by default.) Some applications provide both a CLI and a GUI. The engineering/scientific numerical computation package MATLAB
MATLAB

MATLAB is a Numerical analysis environment and programming language. Maintained by The MathWorks, MATLAB allows easy matrix manipulation, plotting of function and data, implementation of algorithms, creation of user interfaces, and interfacing with programs in other languages....
 provides no GUI for some calculations, but the CLI can handle any calculation. The three-dimensional-modelling program Rhinoceros 3D
Rhinoceros 3D

Rhinoceros is a stand-alone, commercial NURBS-based 3-D modeling tool, developed by Robert McNeel & Associates. The software is commonly used for industrial design, architecture, marine design, jewelry design, automotive design, computer-aided design / computer-aided manufacturing, rapid prototyping, reverse engineering as well as the multim...
  provides a CLI as well as a distinct scripting language. In some computing environments, such as the Oberon
Oberon operating system

Oberon is an operating system, originally developed as part of the NS320xx-based Ceres workstation project; it is written entirely in the Oberon programming language....
 or Smalltalk
Smalltalk

Smalltalk is an Object-oriented programming, Type system, reflection computer programming programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human?computer symbiosis." It was designed and created in part for educational use, more so for constructionist learning, at PARC by Al...
 user interface, most of the text which appears on the screen may be used for giving commands.

Anatomy of a shell CLI


A CLI can generally be considered as consisting of syntax
Syntax

In linguistics, syntax is the study of the principles and rules for constructing Sentence s in natural languages. In addition to referring to the discipline, the term syntax is also used to refer directly to the rules and principles that govern the sentence structure of any individual language, as in "the Irish syntax"....
 and semantics
Semantics

Semantics is the study of meaning in communication. The word is derived from the Greek language word s??a?t???? , "significant", from s??a??? , "to signify, to indicate" and that from s??a , "sign, mark, token"....
. The syntax is the grammar that all commands must follow. In the case of operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
s (OS), MS-DOS
MS-DOS

MS-DOS is an operating system commercialized by Microsoft. It was the most commonly used member of the DOS family of operating systems and was the main operating system for personal computers during the 1980s....
 and Unix
Unix

Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna....
 each define their own set of rules that all commands must follow. In the case of embedded systems, each vendor, such as Nortel
Nortel

Nortel Networks Corporation , formerly known as Northern Telecom Limited and sometimes known simply as Nortel, is a Multinational corporation telecommunications equipment manufacturing headquartered in Toronto, Ontario, Canada....
, Juniper Networks
Juniper Networks

Juniper Networks, Inc. is an information technology and computer networking products multinational company, founded in 1996....
 or Cisco Systems
Cisco Systems

Cisco Systems, Inc. is a multinational corporation with more than 66,000 employees and annual revenue of United States dollar39 billion as of 2008....
, defines their own proprietary set of rules that all commands within their CLI conform to. These rules also dictate how a user navigates through the system of command
Command (computing)

In computing, a command is a directive to a computer program acting as an interpreter of some kind, in order to perform a specific task. Most commonly a command is a directive to some kind of command line interface, such as a shell ....
s. The semantics define what sort of operations are possible, on what sort of data these operations can be performed, and how the grammar represents these operations and data--the symbolic meaning in the syntax.

Two different CLIs may agree on either syntax or semantics, but it is only when they agree on both that they can be considered sufficiently similar to allow users to use both CLIs without needing to learn anything, as well as to enable re-use of scripts.

A simple CLI will display a prompt, accept a "command line" typed by the user terminated by the Enter key
Enter key

In computer Keyboard s, the enter key in most cases causes a command-line interface, window form or dialog box to operate its default function, which is typically to finish an "entry" and begin the desired process....
, then execute the specified command and provide textual display of results or error messages. Advanced CLIs will validate, interpret and parameter-expand the command line before executing the specified command, and optionally capture or redirect its output.

Unlike a button or menu item in a GUI, a command line is typically self-documenting, stating exactly what the user wants done. In addition, command lines usually include many defaults that can be changed to customize the results. Useful command lines can be saved by assigning a character string or alias to represent the full command, or several commands can be grouped to perform a more complex sequence — for instance, compile the program, install it, and run it — creating a single entity, called a command procedure or script which itself can be treated as a command. These advantages mean that a user must figure out a complex command or series of commands only once, because they can be saved, to be used again.

The commands given to a CLI shell are often in one of the following forms:

  • [doSomething] [how] [toFiles]
  • [doSomething] [how] [sourceFile] [destinationFile]
  • [doSomething] [how] < [inputFile] > [outputFile]
  • [doSomething] [how] | [doSomething] [how] | [do Something] [how] > [outputFile]


doSomething is, in effect, a verb
Verb

In syntax, a verb is a word that usually denotes an action , an occurrence , or a state of being . Depending on the language, a verb may vary in form according to many factors, possibly including its grammatical tense, grammatical aspect, grammatical mood and grammatical voice....
, how an adverb
Adverb

An adverb is a part of speech. It is any word that modifies any other part of language: verbs, adjectives , clauses, sentence s and other adverbs, except for nouns; modifiers of nouns are primarily determiners and adjectives....
 (for example, should the command be executed "verbosely" or "quietly") and toFiles an object or objects (typically one or more files) on which the command should act. The '>' in the third example is a redirection operator
Operator (programming)

Programming languages generally support a set of operators that are similar to operator. A language may contain a fixed number of built-in operators or it may allow the creation of programmer-defined operators ....
, telling the command-line interpreter to send the output of the command not to the screen but to the file named on the right of the '>'. This will overwrite the file. Using '>>' will redirect the output and append it to the file. Another redirection operator is the pipe
Vertical bar

The vertical bar has various names including the pipe , verti-bar, vbar, stick, vertical line, vertical slash, think colon, or divider line by others....
 ('|'), which tells the CLI to use the output of one command as the input to the next command; this "operator-stream" mechanism can be very powerful.

Programming languages in interactive mode


Some programming languages (such as BASIC
BASIC

In computer programming, BASIC is a family of high-level programming languages. The Dartmouth BASIC was designed in 1964 by John George Kemeny and Thomas Eugene Kurtz at Dartmouth College in New Hampshire, United States to provide computer access to non-science students....
, Python
Python (programming language)

Python is a general-purpose high-level programming language. Its design philosophy emphasizes code readability. Python's core syntax and semantics are Minimalism , while the standard library is large and comprehensive....
, LISP
Lisp

A lisp is a speech impediment, historically also known as sigmatism. Stereotypically, people with a lisp are unable to pronounce sibilants , and replace them with Interdental consonants , though there are actually several kinds of lisps....
, Forth ...) also provide an interactive command line for experimentation or even for normal everyday work.

CLI and resource protection


In some CLIs, the commands issued are not coupled to any conceptual place within a command hierarchy. A user can specify relative or absolute paths
Path (computing)

A path is the general form of a computer file or directory name, specifying a unique location in a file system. A path points to a file system location by following the directory tree hierarchy expressed in a string of character in which path components, separated by a delimiting character, represent each directory....
 to any command or data. Examples of this include MS-DOS, Windows, and UNIX, which provide forms of a change directory
Chdir

cd, sometimes also available as chdir , is a command line interface command to change the current working directory in operating systems such as Unix, DOS, OS/2 and Microsoft Windows....
 command which allows access to any directory in the system. In some systems, protection of resources is provided by a system of resource ownership by privileged groups, and password-protected user accounts which are members of specific groups. MS-DOS provides no such resource protection, nor do versions of Windows prior to the Windows NT family. (Both of these were designed as single-user systems, where it was assumed that the owner would simply not allow people that she/he did not fully trust to have physical access to the computer at all. UNIX, by contrast, originated as a time-sharing system in corporate and university environments.)

Other CLIs (such as those in network routers) limit the set of commands that a user can perform to a subset, determined by location within a command hierarchy, grouped by association with security, system, interface, etc. The location within this hierarchy and the options available are often referred to as a mode. In these systems the user might traverse through a series of sub-hierarchies, each with their own subset of commands. For example, if the CLI had two modes called interface and system, the user would enter the word 'interface' at the command prompt and then enter an interface mode, where a certain subset of commands and data are available. At this point system commands are not accessible and would not be accessible until the user explicitly exits the interface mode and enters the system mode.

Command prompt


A command prompt (or just prompt) is a sequence of (one or more) characters used in a command-line interface to indicate readiness to accept commands. Its intent is to literally prompt the user to take action. A prompt usually ends with one of the characters $, %, #, :, > and often includes other information, such as the path of the current working directory
Working directory

In computing, the working directory of a process is a directory of a hierarchical file system, if any, dynamically associated with each process....
.

It is common for prompts to be modifiable by the user. Depending on the environment, they may include colors, special characters, and other elements like the current time, in order, for instance, to make the prompt more informative or visually pleasing, to distinguish sessions on various machines, or to indicate the current level of nesting of commands.

In DOS's COMMAND.COM and in the Windows command-line interpreter cmd.exe
Cmd.exe

cmd.exe is the command line interpreter on OS/2, Windows CE and on Windows NT-based operating systems . It is the analog of COMMAND.COM in MS-DOS and Windows 9x systems, or of the Unix shells used on Unix-like systems....
 the prompt is modifiable by issuing a prompt command or by changing the value of the %PROMPT% environment variable
Environment variable

Environment variables are a set of dynamic named Value s that can affect the way running computer process will behave on a computer....
. The default of most modern systems, the C:\> style is obtained, for instance, with "prompt $P$G". The default of older DOS systems, C> is obtained by just "prompt", although on some systems this produces the newer C:\> style; on those systems "prompt $N$G" can be used to switch to the older style.

On many Unix
Unix

Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna....
 systems, the $PS1 variable can be used, although other variables also may have an impact on the prompt (depending on what shell
Unix shell

A Unix shell is a command-line interpreter and script host that provides a traditional user interface for the Unix operating system and for Unix-like systems....
 is being used). In the bash
Bash

Bash is a free software Unix shell written for the GNU Project. Its name is an acronym which stands for Bourne-again shell. The name is a pun on the name of the Bourne shell , an early and important Unix shell written by Stephen Bourne and distributed with Version 7 Unix circa 1978, and the concept of being "Born again Christianity"....
 shell, a prompt of the form
[time] user@host: work_dir $
could be set by issuing the command
export PS1='[\t] \u@\H: \W $'


In zsh the $RPROMPT variable controls an optional "prompt" on the right hand side of the display. It is not a real prompt in that the location of text entry does not change. It is used to display information on the same line as the prompt, but right justified.

In RISC OS, the command prompt is a '*' symbol, and thus (OS)CLI commands are often referred to as "star commands". It is also possible to access the same commands from other command lines (such as the BBC BASIC
BBC BASIC

BBC BASIC is a programming language, developed in 1981 as a native programming language for the MOS Technology 6502 based Acorn Computers BBC Micro home/personal computer, mainly by Sophie Wilson....
 command line), by preceding the command with a '*'.

See also

  • Command-line interpreter
  • Console application
    Console application

    A console application is a computer program designed to be used via a text-only computer interface, such as a text terminal, the command line interface of some Operating system or the text-based interface included with some Graphical user interface operating systems, such as the Win32 console in Microsoft Windows....
  • In the Beginning...was the Command Line
    In the Beginning...was the Command Line

    In the Beginning...was the Command Line is a lengthy essay by Neal Stephenson which was originally published online in 1999 and later made available in book form ....
  • GUI vs. CLI
    Graphical user interface

    A graphical user interface is a type of user interface which allows people to human-computer interaction such as computers; hand-held devices such as MP3 Players, Portable Media Players or Gaming devices; household appliances and office equipment....
  • Scripting language
    Scripting language

    A scripting language, script language or extension language, is a programming language that allows some control of a single or many Application software....
  • Shell (computing)
    Shell (computing)

    In computing, a shell is a piece of software that provides an Interface for users. Typically, the term refers to an operating system shell which provides access to the services of a kernel ....
  • Shell script
    Shell script

    A shell script is a Scripting language written for the Shell , or command line interpreter, of an operating system. It is often considered a simple domain-specific programming language....
  • Run command
    Run command

    On the Microsoft Windows operating system, the Run command is used to directly open an application or document whose Path is known. It functions more or less like a single-line command line interface....
     in Microsoft Windows
  • Command-line argument
  • Terminal emulator
    Terminal emulator

    A terminal emulator, terminal application, term, or tty for short, is a program that emulates a "dumb" video Computer terminal within some other display architecture....


External links

  • — Short book about CLIs by Neal Stephenson.
  • — Device to display CLI as Braille-script.
  • A List and a brief explanation of top Linux commands