IT Fundamentals/2014/Commands and Scripting



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. 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. 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.

Readings

 * 1)  Command-line interface
 * 2)  Pipeline (Unix)
 * 3)  Redirection (computing)
 * 4)  Path (computing)
 * 5)  cmd.exe
 * 6)  Terminal (OS X)
 * 7)  Linux console
 * 8)  Batch file
 * 9)  Shell script

Multimedia

 * 1) YouTube: Windows Command Line Tutorial Part 1
 * 2) YouTube: Windows Command Line Tutorial Part 2
 * 3) YouTube: Terminal Tutorial - Part I: Basic Commands and Concepts
 * 4) YouTube: HakTip - Linux Terminal 101 - Getting Started
 * 5) YouTube: HakTip - Linux Terminal 101 - File Manipulation
 * 6) YouTube: HakTip - Linux Terminal 101 - Wildcards, Hard Links, and Symbolic Links

Activities

 * 1) Complete the tutorial CodeCademy: Learn the Command Line.
 * 2) Identify partitions and file systems installed on your computer system:
 * 3) * Windows: Review Microsoft: A Description of the Diskpart Command-Line Utility. Open a command prompt and use   and the ,  ,  , and   commands to list existing partitions and file systems.
 * 4) * OS X: Review OS X Daily: List All Mounted Drives and their Partitions from the Terminal. Open a Terminal window and use the   command to list existing partitions and file systems.
 * 5) * Linux: Review NixCraft: HowTo: Linux List Disk Partitions Command. Open a Terminal window and use the   command to list existing partitions and file systems.
 * 6) Display and navigate the file system:
 * 7) * Windows: Review Microsoft: Tree Command.
 * 8) *# Open a command prompt and change to the root directory.
 * 9) *# Use the  and   commands to display the directory and directory tree.
 * 10) *# Pipe the output of the directory tree through the more filter using  to view the tree one screen page at a time.
 * 11) *# Redirect the output of the directory tree to a text file using .  Open the tree.txt text file in Notepad and view the results.
 * 12) * OS X: Review MacWorld: Display a tree-like structural view of any directory.
 * 13) *# Open a Terminal window and change to the root directory.
 * 14) *# Use the  and   command to display the directory and directory tree.
 * 15) *# Pipe the output of the directory tree through the more filter using  to view the tree one screen page at a time.
 * 16) *# Redirect the output of the directory tree to a text file using .  Open the tree.txt text file in TextEdit and view the results.
 * 17) * Linux: Review ComputerHope: Linux and Unix Tree Command.
 * 18) *# Open a Terminal window and change to the root directory.
 * 19) *# Use the  and   commands to display the directory and directory tree.
 * 20) *# Pipe the output of the directory tree through the more filter using  to view the tree one screen page at a time.
 * 21) *# Redirect the output of the directory tree to a text file using .  Open the tree.txt text file in gedit and view the results.
 * 22) Create a folder hierarchy and organize files
 * 23) * Windows: Review Colorado.edu: Essential DOS Commands.
 * 24) *# Open a command prompt.
 * 25) *# Use the  (cd) and   (md) commands to create a folder hierarchy.
 * 26) *# Use the  command to organize files within the folder hierarchy.
 * 27) * OS X: Review Archive.org: Learn Code the Hard Way: Command Line Crash Course.
 * 28) *# Open a Terminal window.
 * 29) *# Use the  and   commands to create a folder hierarchy.
 * 30) *# Use the  command to organize files within the folder hierarchy.
 * 31) * Linux: Review Archive.org: Learn Code the Hard Way: Command Line Crash Course.
 * 32) *# Open a Terminal window.
 * 33) *# Use the  and   commands to create a folder hierarchy.
 * 34) *# Use the  command to organize files within the folder hierarchy.
 * 35) Create a script to create a folder hierarchy with a single command.
 * 36) * Windows: Review WikiHow: How to Write a Batch File.
 * 37) *# Open Notepad.
 * 38) *# Add the  commands entered above to the Notepad file.
 * 39) *# Save the file as.
 * 40) *# Open a command prompt and navigate to the location where you saved.
 * 41) *# Type  to run the batch file.
 * 42) * OS X: Review Apple: Shell Script Basics.
 * 43) *# Open TextEdit.
 * 44) *# Start the script with.
 * 45) *# Add the  commands entered above to the TextEdit file.
 * 46) *# Save the file as.
 * 47) *# Open a terminal window and navigate to the location where you saved.
 * 48) *# Type  to change permissions and make the script executable.
 * 49) *# Type  to run the shell script.
 * 50) * Linux: Review LinuxCommand.org: Writing Shell Scripts.
 * 51) *# Open gedit.
 * 52) *# Start the script with.
 * 53) *# Add the  commands entered above to the gedit file.
 * 54) *# Save the file as.
 * 55) *# Open a terminal window and navigate to the location where you saved.
 * 56) *# Type  to change permissions and make the script executable.
 * 57) *# Type  to run the shell script.
 * 58) Review folder and file attributes and permissions.
 * 59) * Windows: Review Microsoft: Managing Permissions from the Command Line.
 * 60) *# Open a command prompt.
 * 61) *# Use the  and   commands to list folder and file attributes and permissions.
 * 62) * OS X: Review PeachPit: Managing Permissions Via Command Line.
 * 63) *# Open a Terminal window.
 * 64) *# Use the  command to list folder and file attributes and permissions.
 * 65) * Linux: Review LinuxCommand.org: Permissions.
 * 66) *# Open a Terminal window.
 * 67) *# Use the  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.
 * 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.
 * 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 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 automate via scripting.
 * 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.
 * A CLI can generally be considered as consisting of syntax and semantics.
 * 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 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 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 an item of information provided to a program when it is started.
 * 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 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 no arguments or one of, 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 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 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 batch files (Windows) or shell scripts (Unix/Linux/OS X).
 * 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 the ASCII vertical bar character "|" (which, for this reason, is often called "pipe character").
 * 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 a function common to most command-line interpreters that can redirect standard streams to user-specified locations.
 * 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.
 * 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 ("..") 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 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.
 * 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 .sh extension, containing a series of commands to be interpreted by the Bash shell. These scripts must begin with   as the first line, and have file permissions set to allow execution.

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.


 * argument
 * A piece of data provided as input to a program, command, or subroutine.


 * attrib
 * A Windows command used to change various characteristics, or attributes of a file or directory.


 * Bash
 * The default command shell on Linux and Mac OS X.


 * cacls
 * A Windows command used to display and modify the security descriptors on folders and files.


 * cd (chdir)
 * A Windows and Unix-like operating system command used to change the current working directory.


 * chmod
 * A Unix-like operating system command used to change the access permissions on files and directories.


 * compiler
 * Transforms source code written in a programming language into binary code to create an executable program.


 * default
 * A setting or a value automatically assigned to a command without user intervention.


 * dir
 * A Windows command used to display file and directory listings.


 * diskpart
 * A Windows command used to manage hard disk partitions.


 * diskutil
 * An OS X command used to manage hard disk partitions


 * environment variable
 * A dynamic named value that can affect the way running processes will behave on a computer.


 * filter
 * A computer program or subroutine that processes an input stream, producing another stream.


 * interpreter
 * Executes source code directly, without first converting the entire program into binary code.


 * ls
 * A Unix-like operating system command used to display file and directory listings.


 * man page (manual page)
 * A form of online software documentation usually found on a Unix or Unix-like operating system.


 * mkdir
 * A Windows and Unix-like operating system command used to make a new directory.


 * more
 * A Windows and Unix-like operating system command used to view the contents of a text file one screen at a time.


 * move
 * A Windows command used to move one or more files or directories from one place to another.


 * mv
 * A command on Unix-like operating systems used to move one or more files or directories from one place to another.


 * parameter
 * A variable that allows for text or data provided as input to a program, command, or subroutine.


 * parted (partition editor)
 * A Linux command used to manage hard disk partitions.


 * PATH
 * An environment variable specifying a set of directories where executable programs are located.


 * 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.


 * relative path
 * A path based on the working directory of the user or application.


 * 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.


 * shell
 * A user interface for access to an operating system's services, using either a command-line interface (CLI) or graphical user interface (GUI).


 * syntax
 * The grammar or rules that define how commands are written.


 * tree
 * A Windows and Unix-like operating system command used to display a recursive directory listing.


 * 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.


 * 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.

Assessments

 * Flashcards: Quizlet: IT Fundamentals - Commands and Scripting
 * Quiz: Quizlet: IT Fundamentals - Commands and Scripting