IT Fundamentals/2014/Commands and Scripting
Appearance
< IT Fundamentals | 2014
(Redirected from IT Fundamentals/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.[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 | edit source]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
[edit | edit source]- Wikipedia: Command-line interface
- Wikipedia: Pipeline (Unix)
- Wikipedia: Redirection (computing)
- Wikipedia: Path (computing)
- Wikipedia: cmd.exe
- Wikipedia: Terminal (OS X)
- Wikipedia: Linux console
- Wikipedia: Batch file
- Wikipedia: Shell script
Multimedia
[edit | edit source]- YouTube: Windows Command Line Tutorial Part 1
- YouTube: Windows Command Line Tutorial Part 2
- YouTube: Terminal Tutorial - Part I: Basic Commands and Concepts
- YouTube: HakTip - Linux Terminal 101 - Getting Started
- YouTube: HakTip - Linux Terminal 101 - File Manipulation
- YouTube: HakTip - Linux Terminal 101 - Wildcards, Hard Links, and Symbolic Links
Activities
[edit | edit source]- Complete the tutorial CodeCademy: Learn the Command Line.
- Identify partitions and file systems installed on your computer system:
- Windows: Review Microsoft: A Description of the Diskpart Command-Line Utility. Open a command prompt and use
diskpart
and thelist disk
,select disk
,list partition
, andlist volume
commands to list existing partitions and file systems. - OS X: Review OS X Daily: List All Mounted Drives and their Partitions from the Terminal. Open a Terminal window and use the
diskutil list
command to list existing partitions and file systems. - Linux: Review NixCraft: HowTo: Linux List Disk Partitions Command. Open a Terminal window and use the
sudo parted -l
command to list existing partitions and file systems.
- Windows: Review Microsoft: A Description of the Diskpart Command-Line Utility. Open a command prompt and use
- Display and navigate the file system:
- Windows: Review Microsoft: Tree Command.
- Open a command prompt and change to the root directory (
cd \
). - Use the
dir
andtree
commands to display the directory and directory tree. - Pipe the output of the directory tree through the more filter using
tree | more
to view the tree one screen page at a time. - 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.
- Open a command prompt and change to the root directory (
- OS X: Review MacWorld: Display a tree-like structural view of any directory.
- Open a Terminal window and change to the root directory (
cd /
). - Use the
ls
andls -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.
- Open a Terminal window and change to the root directory (
- Linux: Review ComputerHope: Linux and Unix Tree Command.
- Open a Terminal window and change to the root directory (
cd /
). - Use the
ls
andtree
commands to display the directory and directory tree. - Pipe the output of the directory tree through the more filter using
tree | more
to view the tree one screen page at a time. - 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.
- Open a Terminal window and change to the root directory (
- Windows: Review Microsoft: Tree Command.
- Create a folder hierarchy and organize files
- Windows: Review Colorado.edu: Essential DOS Commands.
- Open a command prompt.
- Use the
chdir
(cd) andmkdir
(md) commands to create a folder hierarchy. - Use the
move
command to organize files within the folder hierarchy.
- OS X: Review Archive.org: Learn Code the Hard Way: Command Line Crash Course.
- Open a Terminal window.
- Use the
cd
andmkdir
commands to create a folder hierarchy. - Use the
mv
command to organize files within the folder hierarchy.
- Linux: Review Archive.org: Learn Code the Hard Way: Command Line Crash Course.
- Open a Terminal window.
- Use the
cd
andmkdir
commands to create a folder hierarchy. - Use the
mv
command to organize files within the folder hierarchy.
- Windows: Review Colorado.edu: Essential DOS Commands.
- Create a script to create a folder hierarchy with a single command.
- Windows: Review WikiHow: How to Write a Batch File.
- Open Notepad.
- Add the
md
commands entered above to the Notepad file. - Save the file as
"folders.cmd"
. - Open a command prompt and navigate to the location where you saved
folders.cmd
. - Type
folders.cmd
to run the batch file.
- OS X: Review Apple: Shell Script Basics.
- Open TextEdit.
- Start the script with
#!/bin/sh
. - Add the
mkdir
commands entered above to the TextEdit file. - Save the file as
folders.sh
. - Open a terminal window and navigate to the location where you saved
folders.sh
. - Type
chmod 755 folders.sh
to change permissions and make the script executable. - Type
./folders.sh
to run the shell script.
- Linux: Review LinuxCommand.org: Writing Shell Scripts.
- Open gedit.
- Start the script with
#!/bin/sh
. - Add the
mkdir
commands entered above to the gedit file. - Save the file as
folders.sh
. - Open a terminal window and navigate to the location where you saved
folders.sh
. - Type
chmod 755 folders.sh
to change permissions and make the script executable. - Type
./folders.sh
to run the shell script.
- Windows: Review WikiHow: How to Write a Batch File.
- Review folder and file attributes and permissions.
- Windows: Review Microsoft: Managing Permissions from the Command Line.
- Open a command prompt.
- Use the
attrib *.*
andcacls *.*
commands to list folder and file attributes and permissions.
- OS X: Review PeachPit: Managing Permissions Via Command Line.
- Open a Terminal window.
- Use the
ls -l
command to list folder and file attributes and permissions.
- Linux: Review LinuxCommand.org: Permissions.
- Open a Terminal window.
- Use the
ls -l
command to list folder and file attributes and permissions.
- Windows: Review Microsoft: Managing Permissions from the Command Line.
Lesson Summary
[edit | edit source]- 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 | edit source]- 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 | edit source]-
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.
Assessments
[edit | edit source]- Flashcards: Quizlet: IT Fundamentals - Commands and Scripting
- Quiz: Quizlet: IT Fundamentals - Commands and Scripting
See Also
[edit | edit source]- Windows PowerShell
- LifeHacker: Top 10 Tools that are Better in the Command Line
- HowToGeek: Beginners Guide to Shel Scripting
References
[edit | edit source]- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Scripting language
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Pipeline (Unix)
- ↑ Wikipedia: Pipeline (Unix)
- ↑ Wikipedia: Pipeline (Unix)
- ↑ Wikipedia: Redirection (computing)
- ↑ Wikipedia: Redirection (computing)
- ↑ Wikipedia: Redirection (computing)
- ↑ Wikipedia: Path (computing)
- ↑ Wikipedia: Path (computing)
- ↑ Wikipedia: Terminal (OS X)
- ↑ Wikipedia: Linux console
- ↑ Wikipedia: Batch file
- ↑ Wikipedia: Shell script
- ↑ Wikipedia: Path (computing)
- ↑ Wikipedia: Parameter (computer programming)
- ↑ Wikipedia: ATTRIB
- ↑ Wikipedia: Bash (Unix shell)
- ↑ Wikipedia: cacls
- ↑ Wikipedia: cd (command)
- ↑ Wikipedia: chmod
- ↑ Wikipedia: Compiler
- ↑ Wikipedia: Default (computer science)
- ↑ Wikipedia: dir (command)
- ↑ Wikipedia: diskpart
- ↑ Wikipedia: Disk Utility
- ↑ Wikipedia: Environment variable
- ↑ Wikipedia: Filter (software)
- ↑ Wikipedia: Interpreted language
- ↑ Wikipedia: ls
- ↑ Wikipedia: man page
- ↑ Wikipedia: mkdir
- ↑ Wikipedia: more (command)
- ↑ Wikipedia: move (command)
- ↑ Wikipedia: mv
- ↑ Wikipedia: Parameter (computer programming)
- ↑ Wikipedia: GNU Parted
- ↑ Wikipedia: PATH (variable)
- ↑ Wikipedia: Pipeline (Unix)
- ↑ Wikipedia: Path (computing)
- ↑ Wikipedia: Scripting language
- ↑ Wikipedia: Shell (computing)
- ↑ Wikipedia: Command-line interface
- ↑ Wikipedia: Syntax (programming languages)
- ↑ Wikipedia: Tree (Unix)
- ↑ Wikipedia: Path (computing)
- ↑ Wikipedia: Windows PowerShell