L7 Study Guide

¡Supera tus tareas y exámenes ahora con Quizwiz!

The ______ variable represents the BASH shell prompt. To view the contents of this variable only, the user can use the echo command and specify the variable name prefixed with a $ shell metacharacter.

PS1`

___ is a file descriptor that refers to any error messages generated by the command.

Standard Error ( stderr)

___ is a file descriptor that refers to the information processed by the command during execution, and is often takes the form of user input typed on the keyboard.

Standard input (stdin)

Three file descriptors are available to each command that can be manipulated by the BASH shell. Name them.

Standard input (stdin) Standard output (stdout) Standard error (stderr)

___ is a file descriptor that refers to the normal output of a command.

Standard output (stdout)

Every file descriptor is represented by a number. State the file descriptors and their represented numbers.

Stdin is represented by the number 0. Stdout is represented by the number 1. Stderr is represented by the number 2.

T/F. A BASH shell has several variables in memory at any one time.

T

T/F. Both stdout and stderr are displayed on the terminal screen by default.

T

T/F. If the user redirects the Standard Output and Standard Error to the same file without any loss of data, special notation must be used. The following command can be used: ls /etc/hosts /etc/h >goodoutput 2>&1

T

T/F. It is best to redirect the content of Standard Output and Standard Error to two separate files.

T

T/F. Most commands that are run by the shell are run in a separate subshell which was created by the current shell. Any variables created in the current shell are not available to those subshells and the commands running within them.

T

T/F. Piping is commonly used to reduce the amount of information displayed on the terminal screen from commands that display too much information.

T

T/F. Redirecting the Standard Output to a file for later use is more common than redirecting the Standard Error to a file, the BASH shell assumes Standard Output in the absence of a numeric file descriptor, i.e., ls /etc/hosts /etc/h >goodoutput

T

T/F. Redirection and piping can be combined together. Input redirection must occur at the beginning of the pipe and output redirection must occur at end of the pipe.

T

T/F. Redirection only occurs from a command to a file and vice versa. IMPORTANT

T

T/F. Since the output of the set command and the env command is typically large, it is common to redirect the Standard Output of these commands to the grep command to display certain lines only.

T

T/F. Some commands on the Linux system only accept files when they are passed by the shell through Standard Input. Therefore to redirect stdin of a file, the user must use the "<" shell metacharacter.

T

T/F. The BASH shell can be used to redirect stdout and stderr from the terminal screen to a file on the filesystem using the ">" shell metacharacter followed by the absolute or relative pathname of the file.

T

T/F. The BASH shell clears the contents of the goodoutput file if it exists and creates the file if it does not exist. IMPORTANT

T

T/F. The BASH shell is responsible for providing a user interface and interpreting commands entered on the command line. In addition, the BASH shell can manipulate command input and output, provided the user specifies certain shell metacharacters on the command line alongside the command.

T

T/F. The Bash shell clears a file that already exists before performing the redirection. IMPORTANT

T

T/F. The PATH variable is searched in the order that the directories are listed. If the executable file is not in a directory listed in the PATH variable, the user must specify either the absolute or relative pathname to the executable file.

T

T/F. The awk command uses space or tab characters as delimiters for each field in a line. Most configuration files on Linux systems are delimited using the colon (:) character. To change the delimiter that the awk command uses, use the -F option to the command.

T

T/F. The ls and mount commands are not filter commands because they do not accept Standard Input from other commands.

T

T/F. The order of redirection on the command line does not matter.

T

T/F. The user can redirect both Standard Output and Standard Error to separate files at the same time, as shown in the following output, ls /etc/hosts /etc/h >goodoutput 2>badoutput

T

T/F. The user can redirect stdout and stderr to separate files.

T

T/F. The user can send the Standard Output of one command to another command as Standard Input. To do this, the user must use the pipe | shell metacharacter and specify commands on either side. The space before and after the | symbol is optional.

T

T/F. The user can use more than one pipe | metacharacter on the command line to pass information from one command to another over a series of commands.

T

T/F. The user should use separate filenames for stdout and stderr.

T

T/F. To change the value of a variable, the user can specify the variable name followed by the equal sign (=) and the new value.

T

T/F. To create new variables, specify the variable identifier followed by equal sign and the new contents.

T

T/F. To prevent the file from being cleared by the BASH shell and append output to the existing output, you can specify two ">" metacharacters alongside the file descriptor. The following is an example: date >>dateoutput

T

echo $MYVAR

The MYVAR command created a variable that is available to the current shell. The echo command displays the value of the variable.

The features of variable identifiers are the following:

They can contain alphanumeric characters (0 - 9, A - Z, a - z), the dash (-) character, or the underscore (_) character. They must not start with a number. They are typically capitalized to follow convention.

ls /etc/hosts /etc/h 2>badoutput Explain what this command is doing.

This would simply send the stderr to the badoutput file. The stdout is still displayed on the screen because it was not redirected to a file.

______ variables are custom variables that are defined by users.

User-defined

The ______ filter command searches for patterns of text and perform some action on the text found. This command treats each line of text as a record in a database and each word in a line as a database field.

awk

This command displays the sixth and seventh words for lines that contain the word "tom" in the last 10 lines of the file.

tail /etc/passwd | awk -F: '/tom/ {print $6, $7}'

A ______ command is a filter command that takes information from Standard Input and sends that information to a file, as well as to Standard Output.

tee

The ______ command can be used to replace characters in a file sent via Standard Input.

tr

This command takes the prologue file and translates the "a"'s to "A"'s and then sorts the lines in alphabetical order and numbers them. The output is saved as a file called newprologue.

tr a A <prologue | sort | nl > newprologue

It does not modify the /etc/hosts file. It merely translates all of the "l"'s to "L"'s and displays the output on the screen.

tr l L </etc/hosts

It does the same thing as the previous command which is translates all of the "l"'s to "L"'s. However, it does not display the output on the screen but rather saves the output to a file named newhosts.

tr l L </etc/hosts >newhosts

A ______ is a reserved portion of memory containing information that might be accessed.

variable

The ______ is the name of a variable.

variable identifier

Filter commands must be at the ______ of a pipe.

beginning

The ______ command views the contents of a specified variable and uses the prefix $ shell metacharacter.

echo

This command displays the value of the PS1 variable. [\u@h \W\$ \u - user \h - host name \W - name of the current directory

echo $PS1

The ______ command lists all exported environment and user-defined variables in the shell.

env

Most variables in the shell are referred to as ______ variables because they are typically set by the system and contain information that the system and programs access regularly.

environment

The ______ command is used to export user-defined variables to the subshells and it ensures that the programs started by the current shell have access to these variables.

export

Command input and output are represented by labels known as ___ .

file descriptors

A _____ command is any command that can take standard input and transform it to standard output.

filter

This command sends the output of the ls command to the input of the less command.

ls -l /etc | less

This command executes the mount command and displays only those lines in the output dealing with the /dev/sda directory.

mount | grep /dev/sda

A ______ is a string of commands connected by the "|" metacharacters. The shell then sends the stdout on the left to the stdin on the right.

pipe

The syntax of the sed filter command is ____.

s/search/replace/

The ______ filter command searches for a certain string of text and replaces that text string with another text string.

sed

The ______ command can be used to list all environment variables in the BASH shell including user-defined variables.

set

The ______ command lists the environment variables and their current values.

set

This command displays a list of the environment variables that are set by the BASH shell.

set

In addition to environment variables and user-defined variables, ______ variables are available when executing commands and creating new files and directories.

special

A ______ is a shell created by current shell.

subshell

This command displays the first and fourth words only on lines of the prologue file that contains the word "the".

cat prologue | awk '/the/ {print $1, $4}'

This command searches each line of the prologue file that contains the string "love" and replaces all of the strings "the" with the string "THE".

cat prologue | sed /love/s/the/THE/g

This command searches through the prologue file and deletes all of the lines that contain the string "the".

cat prologue | sed /the/d

This command searches lines 5 through 8 of the prologue file for the string "the" and replaces them with the string "THE" globally.

cat prologue | sed 5,8s/the/THE/g

This command searches each line of the prologue file for the word "the" and replaces it with the word "THE". It only replaces the first "the" it finds in each line.

cat prologue | sed s/the/THE/

This command searches each line of the prologue file for the word "the" and replaces it with the word "THE". It now replaces all of the strings "the" it finds globally in the whole document.

cat prologue | sed s/the/THE/g

This command takes the prologue file and translates the "a"'s to "A"'s and then sorts the lines in alphabetical order. In addition, it displays the file on the terminal double spaced and allows the user to view the results page-by-page.

cat prologue | tr a A | sort | pr -d | less

This command takes the prologue file and translates the "a"'s to "A"'s and then sorts the lines in alphabetical order. In addition, it displays the file on the terminal double spaced and allows the user to view the results page-by-page. In addition, it uses the tee command to save a copy of the output as a file called newfile.

cat prologue | tr a A | sort | pr -d | tee newfile | less


Conjuntos de estudio relacionados

Intermediate Microeconomics quiz 10-11

View Set

Excel: Applications, Formatting in Excel Quiz

View Set