A command-line interface (CLI) is a means of interacting with a computer system or program where the user issues commands in the form of successive lines of text.[1] A scripting language is a programming language that supports scripts, programs written for an environment that can interpret (rather than compile) and automate the execution of tasks that could alternatively be executed one-by-one by a human operator.[2] This lesson covers commands and scripting.
Objectives and Skills
Objectives and skills for IT Fundamentals certification are covered in detail in other lessons. This lesson helps you:
Understand operating system commands, scripts, and scripting languages
Understand how scripting language commands a program.
Open a Terminal window and change to the root directory (cd /).
Use the ls and ls -R | grep ":" | sed -e 's/://' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' command to display the directory and directory tree.
Pipe the output of the directory tree through the more filter using ls -R | grep ":" | sed -e 's/://' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' | more to view the tree one screen page at a time.
Redirect the output of the directory tree to a text file using ls -R | grep ":" | sed -e 's/://' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' > tree.txt. Open the tree.txt text file in TextEdit and view the results.
Use the ls -l command to list folder and file attributes and permissions.
Lesson Summary
A command-line interface (CLI) is a means of interacting with a computer program where the user issues commands to the program in the form of successive lines of text.[3]
The interface is usually implemented with a command line shell, which is a program that accepts commands as text input and converts commands to appropriate operating system functions.[4]
Command-line interfaces to computer operating systems are less widely used by casual computer users, who favor graphical user interfaces.[5]
Command-line interfaces are often preferred by more advanced computer users, as they often provide a more concise and powerful means to control a program or operating system.[6]
Programs with command-line interfaces are generally easier to automate via scripting.[7]
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.[8]
A CLI can generally be considered as consisting of syntax and semantics.[9]
The syntax is the grammar that all commands must follow. These rules also dictate how a user navigates through the system of commands.[10]
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.[11]
On many Unix system and derivative systems, it is common for the prompt to end in a $ or% character if the user is a normal user, but in a # character if the user is a superuser (root).[12]
A command-line argument or parameter is an item of information provided to a program when it is started.[13]
A command-line option (also known as a flag or switch) modifies the operation of a command. Options follow the command name on the command line, separated by spaces.[14]
Options may be indicated by one of - -- / ,:?, and may or may not be case-sensitive, depending on the command interpreter.[15]
It is common for a command to be able to display a brief summary of its parameters, typically when invoked with no arguments or one of ? -? -h -H /? /h /H -help --help, but entering a command without parameters in the hope that it will display help will often run the command with default settings.[16]
Command documentation commonly employs a small syntax to describe the valid command form where angle brackets describe required parameters, square brackets indicate optional parameters, ellipses show repeated items, and vertical bars list a choice of items.[17]
Although most users think of the shell as an interactive command interpreter, it is really a programming language in which each statement runs a command.[18]
Most command-line interpreters support scripting to some extent, and such scripts are typically referred to as batch files (Windows) or shell scripts (Unix/Linux/OS X).[19]
A pipeline is a set of processes chained by their standard streams, so that the output of each process feeds directly as input to the next one.[20]
To use the pipeline, one writes the commands in sequence, separated by the ASCII vertical bar character "|" (which, for this reason, is often called "pipe character").[21]
By default, the standard error streams of the processes in a pipeline are not passed on through the pipe; instead, they are merged and directed to the console.[22]
Redirection is a function common to most command-line interpreters that can redirect standard streams to user-specified locations.[23]
Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows, using < to redirect input, and > to redirect output.[24]
To append output to the end of the file, rather than overwriting it, use the >> operator.[25]
Windows paths use a \ to separate folders and filenames. Unix-like operating systems use a / to separate folders and filenames.[26]
In a given path, two dots ("..") point upwards in a path hierarchy to indicate the parent directory. One dot (".") represents the current directory itself.[27]
The command prompt for DOS and Windows operating systems prior to Windows 2000 used the 16-bit COMMAND.COM. Windows NT, Windows 2000 and later operating systems use the 32-bit cmd.exe.
OS X and Linux use the Terminal application to implement a Bash shell interface.[28][29]
Windows batch files, with a .bat or .cmd file extension, are text files containing a series of commands to be executed by the command-line interpreter.[30]
OS X and Linux shell scripts are text files, typically with a .sh extension, containing a series of commands to be interpreted by the Bash shell. These scripts must begin with #!/bin/sh as the first line, and have file permissions set to allow execution.[31]
Key Terms
absolute path
A path that points to the same location on one file system regardless of the present working directory or combined paths.[32]
argument
A piece of data provided as input to a program, command, or subroutine.[33]
attrib
A Windows command used to change various characteristics, or attributes of a file or directory.[34]
Bash
The default command shell on Linux and Mac OS X.[35]
cacls
A Windows command used to display and modify the security descriptors on folders and files.[36]
cd (chdir)
A Windows and Unix-like operating system command used to change the current working directory.[37]
chmod
A Unix-like operating system command used to change the access permissions on files and directories.[38]
compiler
Transforms source code written in a programming language into binary code to create an executable program.[39]
default
A setting or a value automatically assigned to a command without user intervention.[40]
dir
A Windows command used to display file and directory listings.[41]
diskpart
A Windows command used to manage hard disk partitions.[42]
diskutil
An OS X command used to manage hard disk partitions[43]
environment variable
A dynamic named value that can affect the way running processes will behave on a computer.[44]
filter
A computer program or subroutine that processes an input stream, producing another stream.[45]
interpreter
Executes source code directly, without first converting the entire program into binary code.[46]
ls
A Unix-like operating system command used to display file and directory listings.[47]
man page (manual page)
A form of online software documentation usually found on a Unix or Unix-like operating system.[48]
mkdir
A Windows and Unix-like operating system command used to make a new directory.[49]
more
A Windows and Unix-like operating system command used to view the contents of a text file one screen at a time.[50]
move
A Windows command used to move one or more files or directories from one place to another.[51]
mv
A command on Unix-like operating systems used to move one or more files or directories from one place to another.[52]
parameter
A variable that allows for text or data provided as input to a program, command, or subroutine.[53]
parted (partition editor)
A Linux command used to manage hard disk partitions.[54]
PATH
An environment variable specifying a set of directories where executable programs are located.[55]
pipeline
a set of processes chained by their standard streams, so that the output of each process feeds directly as input to the next process.[56]
relative path
A path based on the working directory of the user or application.[57]
script
Programs written for a special run-time environment that can interpret (rather than compile) and automate the execution of tasks that could alternatively be executed one-by-one by a human operator.[58]
shell
A user interface for access to an operating system's services, using either a command-line interface (CLI) or graphical user interface (GUI).[59]
syntax
The grammar or rules that define how commands are written.[60][61]
tree
A Windows and Unix-like operating system command used to display a recursive directory listing.[62]
UNC (Universal Naming Convention)
A common syntax used by Windows to describe the location of a network resource, such as a shared file, directory, or printer using the form \\ComputerName\SharedFolder\Resource.[63]
Windows PowerShell
A task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework.[64]
Review Questions
A command-line interface (CLI) is _____.
A command-line interface (CLI) is a means of interacting with a computer program where the user issues commands to the program in the form of successive lines of text.
Command-line interfaces to computer operating systems are less widely used by _____.
Command-line interfaces to computer operating systems are less widely used by casual computer users, who favor graphical user interfaces.
Command-line interfaces are often preferred by _____.
Command-line interfaces are often preferred by more advanced computer users, as they often provide a more concise and powerful means to control a program or operating system.
Programs with command-line interfaces are generally easier to _____.
Programs with command-line interfaces are generally easier to automate via scripting.
A command prompt is _____.
A command prompt is a sequence of characters used in a command-line interface to indicate readiness to accept commands.
A CLI can generally be considered as consisting of _____ and _____.
A CLI can generally be considered as consisting of syntax and semantics.
The syntax is _____.
The syntax is the grammar that all commands must follow. These rules also dictate how a user navigates through the system of commands.
The semantics define _____.
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.
On many Unix system and derivative systems, it is common for the prompt to end in _____.
On many Unix system and derivative systems, it is common for the prompt to end in a $ or% character if the user is a normal user, but in a # character if the user is a superuser (root).
A command-line argument or parameter is _____.
A command-line argument or parameter is an item of information provided to a program when it is started.
A command-line option _____. Options follow the command name on the command line, separated by _____.
A command-line option (also known as a flag or switch) modifies the operation of a command. Options follow the command name on the command line, separated by spaces.
Options may be indicated by one of _____ and may or may not be _____, depending on the command interpreter.
Options may be indicated by one of - -- / ,:?, and may or may not be case-sensitive, depending on the command interpreter.
It is common for a command to be able to display a brief summary of its parameters, typically when invoked with _____, but _____.
It is common for a command to be able to display a brief summary of its parameters, typically when invoked with no arguments or one of? -? -h -H /? /h /H -help --help, but entering a command without parameters in the hope that it will display help will often run the command with default settings.
Command documentation commonly employs a small syntax to describe the valid command form where angle brackets describe _____, square brackets indicate _____, ellipses show _____, and vertical bars list _____.
Command documentation commonly employs a small syntax to describe the valid command form where angle brackets describe required parameters, square brackets indicate optional parameters, ellipses show repeated items, and vertical bars list a choice of items.
Although most users think of the shell as an interactive command interpreter, it is really _____.
Although most users think of the shell as an interactive command interpreter, it is really a programming language in which each statement runs a command.
Most command-line interpreters support scripting to some extent, and such scripts are typically referred to as _____ or _____.
Most command-line interpreters support scripting to some extent, and such scripts are typically referred to as batch files (Windows) or shell scripts (Unix/Linux/OS X).
A pipeline is _____.
A pipeline is a set of processes chained by their standard streams, so that the output of each process feeds directly as input to the next one.
To use the pipeline, one writes the commands in sequence, separated by _____.
To use the pipeline, one writes the commands in sequence, separated by the ASCII vertical bar character "
By default, the standard error streams of the processes in a pipeline are not passed on through the pipe; instead, they are _____.
By default, the standard error streams of the processes in a pipeline are not passed on through the pipe; instead, they are merged and directed to the console.
Redirection is _____.
Redirection is a function common to most command-line interpreters that can redirect standard streams to user-specified locations.
Redirection is usually implemented by _____.
Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows, using < to redirect input, and > to redirect output.
To append output to the end of the file, rather than overwriting it, use the _____ operator.
To append output to the end of the file, rather than overwriting it, use the >> operator.
Windows paths use a _____ to separate folders and filenames. Unix-like operating systems use a _____ to separate folders and filenames.
Windows paths use a \ to separate folders and filenames. Unix-like operating systems use a / to separate folders and filenames.
In a given path, two dots ("..") _____. One dot (".") represents _____.
In a given path, two dots ("..") point upwards in a path hierarchy to indicate the parent directory. One dot (".") represents the current directory itself.
The command prompt for DOS and Windows operating systems prior to Windows 2000 used _____. Windows NT, Windows 2000 and later operating systems use _____.
The command prompt for DOS and Windows operating systems prior to Windows 2000 used the 16-bit COMMAND.COM. Windows NT, Windows 2000 and later operating systems use the 32-bit cmd.exe.
OS X and Linux use _____ to implement a _____ shell interface.
OS X and Linux use the Terminal application to implement a Bash shell interface.
Windows batch files, with a _____ file extension, are text files containing _____.
Windows batch files, with a .bat or .cmd file extension, are text files containing a series of commands to be executed by the command-line interpreter.
OS X and Linux shell scripts are text files, typically with a _____ extension, containing _____. These scripts must begin with _____ as the first line, and have file permissions set to _____.
OS X and Linux shell scripts are text files, typically with a .sh extension, containing a series of commands to be interpreted by the Bash shell. These scripts must begin with #!/bin/sh as the first line, and have file permissions set to allow execution.