IT Fundamentals/Commands and Scripting

From Wikiversity
Jump to: navigation, search
Nuvola apps konsole.png

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[edit]

Objectives and skills for for IT Fundamentals certification are covered in detail in other lessons. This lesson helps you:

  • Understand operating system commands, scripts, and scripting languages

Readings[edit]

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

Multimedia[edit]

  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[edit]

  1. Complete the tutorial CodeCademy: Learn the Command Line.
  2. Identify partitions and file systems installed on your computer system:
  3. Display and navigate the file system:
    • Windows: Review Microsoft: Tree Command.
      1. Open a command prompt and change to the root directory (cd \).
      2. Use the dir and tree commands to display the directory and directory tree.
      3. Pipe the output of the directory tree through the more filter using tree | more to view the tree one screen page at a time.
      4. Redirect the output of the directory tree to a text file using tree > tree.txt. Open the tree.txt text file in Notepad and view the results.
    • OS X: Review MacWorld: Display a tree-like structural view of any directory.
      1. Open a Terminal window and change to the root directory (cd /).
      2. 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.
      3. 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.
      4. 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.
    • Linux: Review ComputerHope: Linux and Unix Tree Command.
      1. Open a Terminal window and change to the root directory (cd /).
      2. Use the ls and tree commands to display the directory and directory tree.
      3. Pipe the output of the directory tree through the more filter using tree | more to view the tree one screen page at a time.
      4. Redirect the output of the directory tree to a text file using tree > tree.txt. Open the tree.txt text file in gedit and view the results.
  4. Create a folder hierarchy and organize files
  5. Create a script to create a folder hierarchy with a single command.
    • Windows: Review WikiHow: How to Write a Batch File.
      1. Open Notepad.
      2. Add the md commands entered above to the Notepad file.
      3. Save the file as "folders.cmd".
      4. Open a command prompt and navigate to the location where you saved folders.cmd.
      5. Type folders.cmd to run the batch file.
    • OS X: Review Apple: Shell Script Basics.
      1. Open TextEdit.
      2. Start the script with #!/bin/sh.
      3. Add the mkdir commands entered above to the TextEdit file.
      4. Save the file as folders.sh.
      5. Open a terminal window and navigate to the location where you saved folders.sh.
      6. Type chmod 755 folders.sh to change permissions and make the script executable.
      7. Type ./folders.sh to run the shell script.
    • Linux: Review LinuxCommand.org: Writing Shell Scripts.
      1. Open gedit.
      2. Start the script with #!/bin/sh.
      3. Add the mkdir commands entered above to the gedit file.
      4. Save the file as folders.sh.
      5. Open a terminal window and navigate to the location where you saved folders.sh.
      6. Type chmod 755 folders.sh to change permissions and make the script executable.
      7. Type ./folders.sh to run the shell script.
  6. Review folder and file attributes and permissions.

Lesson Summary[edit]

  • 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[edit]

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[edit]

Enable JavaScript to hide answers.
Click on a question to see the answer.
  1. 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.
  2. 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.
  3. 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.
  4. Programs with command-line interfaces are generally easier to _____.
    Programs with command-line interfaces are generally easier to automate via scripting.
  5. A command prompt is _____.
    A command prompt is a sequence of characters used in a command-line interface to indicate readiness to accept commands.
  6. A CLI can generally be considered as consisting of _____ and _____.
    A CLI can generally be considered as consisting of syntax and semantics.
  7. 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.
  8. 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.
  9. 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).
  10. 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.
  11. 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.
  12. 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.
  13. 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.
  14. 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.
  15. 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.
  16. 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).
  17. 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.
  18. 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 "
  19. 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.
  20. Redirection is _____.
    Redirection is a function common to most command-line interpreters that can redirect standard streams to user-specified locations.
  21. 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.
  22. 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.
  23. 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.
  24. 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.
  25. 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.
  26. OS X and Linux use _____ to implement a _____ shell interface.
    OS X and Linux use the Terminal application to implement a Bash shell interface.
  27. 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.
  28. 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.

Assessments[edit]

See Also[edit]

References[edit]

Nuvola apps edu miscellaneous.svg Type classification: this is a lesson resource.
Progress-1000.svg Completion status: this resource is considered to be complete.
  1. Wikipedia: Command-line interface
  2. Wikipedia: Scripting language
  3. Wikipedia: Command-line interface
  4. Wikipedia: Command-line interface
  5. Wikipedia: Command-line interface
  6. Wikipedia: Command-line interface
  7. Wikipedia: Command-line interface
  8. Wikipedia: Command-line interface
  9. Wikipedia: Command-line interface
  10. Wikipedia: Command-line interface
  11. Wikipedia: Command-line interface
  12. Wikipedia: Command-line interface
  13. Wikipedia: Command-line interface
  14. Wikipedia: Command-line interface
  15. Wikipedia: Command-line interface
  16. Wikipedia: Command-line interface
  17. Wikipedia: Command-line interface
  18. Wikipedia: Command-line interface
  19. Wikipedia: Command-line interface
  20. Wikipedia: Pipeline (Unix)
  21. Wikipedia: Pipeline (Unix)
  22. Wikipedia: Pipeline (Unix)
  23. Wikipedia: Redirection (computing)
  24. Wikipedia: Redirection (computing)
  25. Wikipedia: Redirection (computing)
  26. Wikipedia: Path (computing)
  27. Wikipedia: Path (computing)
  28. Wikipedia: Terminal (OS X)
  29. Wikipedia: Linux console
  30. Wikipedia: Batch file
  31. Wikipedia: Shell script
  32. Wikipedia: Path (computing)
  33. Wikipedia: Parameter (computer programming)
  34. Wikipedia: ATTRIB
  35. Wikipedia: Bash (Unix shell)
  36. Wikipedia: cacls
  37. Wikipedia: cd (command)
  38. Wikipedia: chmod
  39. Wikipedia: Compiler
  40. Wikipedia: Default (computer science)
  41. Wikipedia: dir (command)
  42. Wikipedia: diskpart
  43. Wikipedia: Disk Utility
  44. Wikipedia: Environment variable
  45. Wikipedia: Filter (software)
  46. Wikipedia: Interpreted language
  47. Wikipedia: ls
  48. Wikipedia: man page
  49. Wikipedia: mkdir
  50. Wikipedia: more (command)
  51. Wikipedia: move (command)
  52. Wikipedia: mv
  53. Wikipedia: Parameter (computer programming)
  54. Wikipedia: GNU Parted
  55. Wikipedia: PATH (variable)
  56. Wikipedia: Pipeline (Unix)
  57. Wikipedia: Path (computing)
  58. Wikipedia: Scripting language
  59. Wikipedia: Shell (computing)
  60. Wikipedia: Command-line interface
  61. Wikipedia: Syntax (programming languages)
  62. Wikipedia: Tree (Unix)
  63. Wikipedia: Path (computing)
  64. Wikipedia: Windows PowerShell