LINUX Shell Commands

Ace your homework & exams now with Quizwiz!

Which of the following are true statements about SQL tables? (Select two.) A. Multiple tables may exist in a single SQL database. B. Tables may be combined for cross-table searches using the DROP command. C. Tables consist of rows, each of which holds attributes, and columns, each of which defines a specific database item. D. Careful table design can reduce the amount of data entry and database storage size. E. Tables are stored on disk using a lossy compression algorithm.

A, D. A single database may hold multiple tables, as option A suggests. Option D is also correct; if data is split across tables (such as into tables describing objects generically and specifically), databases can be more space efficient. Option B is incorrect because the DROP command doesn't combine tables—it deletes a table! Option C is incorrect because it reverses the meaning of rows and columns in a SQL table. A lossy compression algorithm, as the name suggests, deliberately corrupts or loses some data—an unacceptable option for a text database, making option E incorrect. (Lossy compression is used for some audio and video file formats, though.)

What commands might you use (along with appropriate options) to learn the value of a specific environment variable? (Select two.) A. env B. DISPLAY C. export D. echo E. cat

A, D. The env command displays all defined environment variables, so option A satisfies the question. (In practice, you might pipe the results through grep to find the value of a specific environment variable.) The echo command, when passed the name of a specific environment variable, displays its current value, so option D is also correct. DISPLAY is an environment variable, but it's not a command for displaying environment variables, so option B is incorrect. You can use the export command to create an environment variable but not to display the current settings for one, so option C is incorrect. Option E's cat command concatenates files or displays the contents of a file to the screen, but it doesn't display environment variables.

If typed in a bash shell, which of the following commands will create an environment variable called MYVAR with the contents mystuff that will be accessible to any created subshells? (Choose all that apply.) A. export MYVAR='mystuff' B. MYVAR='mystuff' C. MYVAR='mystuff'; export MYVAR D. echo $MYVAR mystuff E. setenv MYVAR mystuff

A, C. Option A creates the desired environment variable. Option C also creates the desired environment variable. It combines the variable setting and the export of the MYVAR variable using a different method than option A uses. It combines the two commands on one line using a semicolon (;). Option B creates a local variable—but not an environment variable—called MYVAR, holding the value mystuff. After typing option B, you can also type export MYVAR to achieve the desired goal, but option B by itself is insufficient. Option D displays the contents of the MYVAR variable and also echoes mystuff to the screen, but it doesn't change the contents of any environment variable. Option E's setenv isn't a valid bash command, but it will set an environment variable in tcsh.

You see the following line in a script: mail -s "Error" -c abort < /tmp/msg root What is the effect of this line, if and when it executes? A. An email is sent to the user Error, the script is aborted using root privileges, and error messages are written to /tmp/msg. B. An email with the subject of Error and the contents from /tmp/msg is sent to the local users root and abort. C. An email with the subject of Error and the contents of /tmp/msg is sent to the local user root, and then the script is aborted. D. An email is sent with Error priority to the local user root, and the email system is then shut down with error messages being stored in /tmp/msg. E. An email with the subject of Error and contents of /tmp/msg is sent to root, and information on this is logged with priority abort.

B. The -s option to mail sets the message subject line, and -c sets carbon copy (cc:) recipients. Input redirection (via <) reads the contents of a line into mail as a message. A mail command line normally terminates with the primary recipient. Thus, option B correctly describes the effect of the specified line. Options A, C, D, and E are all confused in their interpretation of the effects of mail parameters. Options A, B, and D also confuse input and output redirection, and option A incorrectly suggests that a script (or the mail program) can elevate its run status to root privileges.

You examine your /etc/aliases file and find that it contains the following line: root: jody What can you conclude from this? A. Email addressed to jody on this system will be sent to the local user root. B. Email addressed to root on this system will be sent to the local user jody. C. The local user jody has broken into the system and has acquired root privileges. D. The local user jody has permission to read email directly from root's mail queue. E. The administrator may log in using either username: root or jody.

B. The /etc/aliases file configures system-wide email forwarding. The specified line does as option B describes. A configuration like this one is common. Option A has things reversed. Option C is not a valid conclusion from this evidence alone, although an intruder conceivably may be interested in redirecting root's email, so if jody shouldn't be receiving root's email, this should be investigated further. Although the effect of option D (jody reading root's email) is nearly identical to the correct answer's effect, they are different; jody cannot directly access the file or directory that is root's email queue. Instead, the described configuration redirects root's email into jody's email queue. Thus, option D is incorrect. Because /etc/aliases is an email configuration file, not an account configuration file, it can't have the effect described in option E.

You've just installed MySQL and run it by typing mysql. How would you create a database called fish to store data on different varieties of fish? A. Type NEW DATABASE fish; at the mysql> prompt. B. Type CREATE DATABASE fish; at the mysql> prompt. C. Type NEW DATABASE FISH; at the mysql> prompt. D. Type DATABASE CREATE fish; at the mysql> prompt. E. Type DB CREATE fish; at the mysql> prompt.

B. The CREATE DATABASE command creates a new database with the specified name. Because SQL commands are case insensitive, this command may be typed in uppercase or lowercase, and option B is correct. Options A and C both use the incorrect command NEW rather than CREATE, and option C specifies the database name as FISH rather than fish. (Database names are case sensitive.) Option D reverses the order of the CREATE and DATABASE keywords. Option E uses the fictitious command DB.

Your SMTP email server receives a message addressed to postmaster. The postmaster username has an alias of john on this computer. Assuming that the system is properly configured, who will receive the email message? A. postmaster B. john C. The account listed in ~/.forward D. root E. No user, because an alias was set

B. When aliases are properly configured, any email addresses sent to the email with an alias is received by the alias account. Therefore, option B is correct. The postmaster username would not receive the email because the alias is set to john, and so option A is incorrect. The ~/.forward file is associated with email forwarding, not aliases. Therefore, option C is incorrect. There is no reason for root to receive this email, so option D is incorrect. An alias does allow email to be sent to the alias account, so the statement in Option E does not make sense and is incorrect.

Which of the following is not a popular SMTP server for Linux? A. Postfix B. Sendmail C. Fetchmail D. Exim E. qmail

C. The Fetchmail program is a tool for retrieving email from remote POP or IMAP servers and injecting it into a local (or remote) SMTP email queue. As such, it's not an SMTP server, so option C is correct. Postfix (option A), sendmail (option B), Exim (option D), and qmail (option E) are all popular SMTP email servers for Linux.

What is the effect of the following SQL command, assuming the various names and data exist? mysql> UPDATE stars SET magnitude=2.25 WHERE starname='Mintaka'; A. It returns database entries from the stars table for all stars with magnitude of 2.25 and starname of Mintaka. B. It sets the value of the stars field in the magnitude set to Mintaka, using a precision of 2.25. C. It sets the value of the magnitude field to 2.25 for any item in the stars table with the starname value of Mintaka. D. It combines the stars and magnitude=2.25 tables, returning all items for which the starname is Mintaka. E. It updates the stars database, creating a new entry with a starname value of Mintaka and a magnitude of 2.25 .

C. The UPDATE command modifies existing database table entries, and in this case it does so as option C describes. Option B also describes an update operation, but in a confused and incorrect way. Options A and D both describe database retrieval operations, but UPDATE doesn't retrieve data. Option E mistakenly identifies stars as a database name, but it's a table name, and it mistakenly identifies the operation as adding a new entry (INSERT in SQL) rather than as modifying an existing entry (UPDATE in SQL).

Describe the effect of the following short script, cp1.sh, if it's called as cp1.sh big.c big.cc: #!/bin/bash cp $2 $1 A. It has the same effect as the cp command—copying the contents of big.c to big.cc. B. It compiles the C program big.c and calls the result big.cc. C. It copies the contents of big.cc to big.c, eliminating the old big.c. D. It converts the C program big.c into a C++ program called big.cc. E. It interprets the big.c and big.cc files as bash scripts.

C. The cp command is the only one called in the script, and that command copies files. Because the script passes the arguments ($1 and $2) to cp in reverse order, their effect is reversed—where cp copies its first argument to the second name, the cp1.sh script copies the second argument to the first name. Thus, option C is correct. Because the order of arguments to cp is reversed, option A is incorrect. The cp command has nothing to do with compiling (option B) or converting (option D) C or C++ programs, so neither does the script. The reference to /bin/bash in the first line of the script identifies the script itself as being a bash script; it does not cause the arguments to the script to be run as bash scripts, so option E is incorrect.

Your Internet connection has gone down for several hours. What command can you use to check if there is a long list of jobs in the email queue? A. service sendmail status B. lp -d queue ~/Maildir C. sendmail -bq D. mailq E. ls /var/spool

D. To view your mail queue, use the mailq command (option D). The service sendmail status command is a SysV service status command and does not show mail queues, so option A is incorrect. Option B is a printer command and is therefore incorrect. Option C is close, but the correct command is sendmail -bp not -bq. Option E will show you the various directories within /var/spool and is therefore not the correct command.

What file might a user modify to alter their own bash environment? A. /etc/inputrc B. /etc/bashrc C. $HOME/bashrc D. $HOME/.profile_bash E. ~/.bashrc

E. The ~/.bashrc file is a non-login bash startup script file. As such, it can be used to alter a user's bash environment, and option E is correct. The /etc/inputrc file is a global bash configuration file for keyboard customization and setting terminal behavior. The ~/.inputrc file is for users to create or modify their own keyboard configuration file. Therefore, option A is incorrect. The /etc/bashrc file is a global bash startup script. Editing it will modify users' bash environments, but an individual user should not be able to modify it, so option B is incorrect. There is no standard $HOME/bashrc file because the filename is missing its prefixed period (.). Thus, option C is incorrect. Likewise, option D's $HOME/.profile_bash doesn't refer to a user's configuration file and is incorrect. However, there is a $HOME/.bash_profile bash configuration file.

What is the purpose of the EDITOR environment variable?

Some programs refer to EDITOR to determine what external editor to launch when they need to launch one.

Which environment variable stores the format for the command prompt?

The PS1 environment variable contains various formatting codes preceded by a backslash (\) as well as text to be included in the primary command prompt.

In what environment variable is the current working directory stored? PWD

The PWD environment variable holds the present working directory, so option C is correct. The PATH environment variable (option A) holds a colon-delimited list of directories in which executable programs are stored so that they may be run without specifying their complete pathnames.

You want to create a shortcut command for the command cd ~/papers/trade. Which of the following lines, if entered in a bash startup script, will accomplish this goal? A. alias cdpt='cd ~/papers/trade'

The alias built-in command creates a duplicate name for a (potentially much longer) command. Option A shows the correct syntax for using this built-in command. It causes the new alias cdpt to work like the much longer cd ~/papers/trade.

Which of the following are valid looping statements in bash shell scripting? (Select all that apply.) A. for B. while C. if-then D. until E. case

A, B, D. The for, while, and until statements are all valid looping statements in bash, so options A, B, and D are all correct. The if-then statement in bash's scripting language tests a condition and, if it is true, executes its commands one time only. Therefore, option C is incorrect. The case statement is a conditional, not a looping statement in bash, so option E is incorrect.

Which of the following lines identify valid shell scripts on a normally configured system? (Select two.) A. #!/bin/script B. #!/bin/bash C. #!/bin/tcsh D. !#/bin/sh E. !#/bin/zsh

B, C. Valid shell scripts begin with the characters #! and the complete path to a program that can run the script. Options B and C both meet this description, because /bin/bash is a shell program that's installed on virtually all Linux systems and /bin/ tcsh is often also available. There is no standard /bin/script program, so option A is incorrect. Options D and E are both almost correct; /bin/sh is typically linked to a valid shell and /bin/zsh is a valid shell on many systems, but the order of the first two characters is reversed, so these options are incorrect.

Immediately after creating a shell script called a_script.sh in a text editor, which method will not work to run the script? A. Typing bash a_script.sh at the command line. B. Typing ./a_script.sh at the command line. C. Typing . a_script.sh at the command line. D. Typing source a_script.sh at the command line. E. Any of the above will work.

B. Before using the ./ execution method, the script must have at least one executable bit set. Therefore, an error will be generated since chmod was not used to modify the execute permissions on the a_script file. Thus Option B is the correct choice since it would not work. Option A uses the bash command to execute a script, and this will work fine without any file permission changes. Likewise, when you source a file using either the source command or a dot (.) and a space, there is no need to modify a scripts permission bits before executing the file. Therefore, option C and option D are incorrect because they also work fine.

Where are the commands iterated by the loop located within the loop? A. Within the then statement section B. Between the double semicolons (;;) C. Within the case and esac constructs D. Within the test statement E. Between do and done constructs

E. The commands iterated by the for, while, and until loops are located between the do and done constructs. Therefore, option E is correct. Commands in the then statement section are for an if-then construct, not a loop, thus option A is incorrect. Double semicolons are used for case constructs, but not loops, and so option B is incorrect. The case and esac keywords begin and end a case construct, and thus option C is incorrect. A test statement can be used to determine whether or not a loop's commands should iterate or not. However, it does not contain the actual commands to be iterated, and therefore option D is incorrect.


Related study sets

Ultimate! AP Psych Study Questions

View Set

License Suspension, Revocation, and Reinstatement

View Set

Factors that shift the demand curve

View Set

Psychology - Chapter 15: Psychological Disorders

View Set

BIO 3100 - CH 7 Pre Class Assignment

View Set

Development of the Fetal Heart & Circulation

View Set

Psych Methods 2314 B Sessions 5.1, 5.2, 5.3

View Set

Chapter 11 Biology DNA and Genetics

View Set