Unix ITN 171 - Exam 3 study guide

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Write a Perl script to display the line "Perl was developed by Larry Wall."

#!/usr/bin/perl # Program name: exercise1.pl print ("Perl was developed by Larry Wall\n");

Write a Perl program that contains a hash variable and displays the keys. The hash variable contains the following key and value combinations: Key Value 1 Martin 2 Hanson 3 Stephens 4 Rawlins

#!/usr/bin/perl # Program name: exercise10.pl %peoplelist = ('Martin', 1, 'Hanson', 2, 'Stephens', 3, 'Rawlins', 4); print ("The keys are:\n"); print ("$peoplelist{'Martin'}\n"); print ("$peoplelist{'Hanson'}\n"); print ("$peoplelist{'Stephens'}\n"); print ("$peoplelist{'Rawlins'}\n");

Write a Perl script in which you create a variable in the script to contain the name Beth and then have the script display "Welcome Beth."

#!/usr/bin/perl # Program name: exercise2.pl $name = "Beth"; print ("Welcome $name\n");

Modify the script you wrote in Exercise 2 so that you prompt for the name and then display "Welcome name."

#!/usr/bin/perl # Program name: exercise3.pl print ("Enter your first name: "); $name = <STDIN>; print ("Welcome $name\n");

Create a Perl program that uses an array of vegetables—peas, carrots, spinach, corn, beans—and in which all of the vegetables in the array are displayed to the screen

#!/usr/bin/perl # Program name: exercise5.pl @vegetables = ("peas", "carrots", "spinach", "corn", "beans"); print ("The vegetables on my list are:\n"); print ("$vegetables[0]\n"); print ("$vegetables[1]\n"); print ("$vegetables[2]\n"); print ("$vegetables[3]\n"); print ("$vegetables[4]\n");

Write a Perl program that attempts to open a file that does not exist, and that prints the message "That file is nonexistent."

#!/usr/bin/perl # Program name: exercise7.pl open (FILEIN, "nofile") || warn "Could not open students file\n";

Write a Perl program that converts a value in inches to a value in centimeters and displays the result. (1 inch = 2.54 centimeters.)

#!/usr/bin/perl # Program name: exercise8.pl print ("Enter a number of inches: "); $inches = <STDIN>; $cent = $inches * 2.54; print ("That is $cent centimeters\n");

Design a Perl program that sorts the last names Martin, Adams, Sandoval, Perry, Yablonsky, Brown, and Ramirez.

#!/usr/bin/perl #Program name: exercise6.pl @namelist = (Martin, Adams, Sandoval, Perry, Yablonsky, Brown, Ramirez); @sortednames = sort @namelist; print "@sortednames"; print"\n";

Write down four scalar variables, two of which are numeric and two that are strings.

$value = 45; $m = 90; $furniture = "desk"; $car = "Ford";

Which of the following characters are placed right after a function name when you create a shell function? a. ( ) b. !# c. [[ d. //

( )

Which of the following are examples of Boolean operators used with the test command? (Choose all that apply.) a. -a for a logical AND b. -m for a partial MERGE c. -n for logical NEGATION d. -o for a logical OR

-a for a logical AND -o for a logical OR

Some Linux systems use the script to perform the same actions each time a user logs out of her account. a. .bash_logout b. .bash_rc c. /bin/bashout d. /etc/logoff_bash

.bash_logout

In your organization everyone uses the Bash shell in Red Hat Enterprise Linux and all users use the same aliases and shell functions. In what file or files can the system administrator place these aliases and functions so they are available to all users?

/etc/.bashrc /etc/profile

In which of the following files would a system administrator set the default shell used by your account? a. .shell b. /home/shell c. /etc/passwd d. /home

/etc/passwd

Which of the following are levels of backups that can be made with the dump command? (Choose all that apply.) a. 0 b. 5 c. 15 d. 20

0 5

When you enter echo $CLR your screen clears very quickly.Which of the following commands must you have entered previously to enable use of echo $CLR to clear the screen? a. set =:clear b. let clear=CLR c. $clear=CLR d. CLR='clear'

CLR = `clear`

Your company has assigned you to revise 22 scripts. Since you use the vi editor, how can you set it to automatically display lines as numbered so it is easier for you to work on these revisions? a. Create a vi macro that enables you view the lines as numbered when you press n in the command mode. b. Create the .exrc file in your home directory so this file contains the line: set number. c. Type set_lines and press Enter before you start vi. d. Press # while you are in the ex mode in vi.

Create the .exrc file in your home directory so this file contains the line :set number

How can you best ensure that the Bash shell is invoked when this script is run? a. Have the script print a warning to the screen that it requires the Bash shell. b. Have the system administrator adjust all faculty accounts so the Bash shell is the default. c. Enter the line # !/ bin/bash as the first line in the script. d. Create a function for all faculty user accounts that prevents use of shells other than Bash.

Enter the line # !/ bin/bash as the first line in the script.

Create a Perl program that sorts the numbers 115, 10, 19, 35, and 2 and that uses the spaceship operator to accomplish the sort.

First create a data file, such as a file called number list that contains the numbers 115, 10, 19, 35, and 2 (with each number on a separate line). #!/usr/bin/perl # Program name: exercise9.pl $x = 0; while (<>) { $somelist[$x] = $_; $x++; } @sortedlist = sort numbers @somelist; print @sortedlist; sub numbers { $a <=> $b } chmod./exercise9.pl numberlist

In the following command, what is the purpose of -o? find . "( " -name a.out -o -name core ")" a. It tests for the existence of files. b. It is the "OR" operator. c. It directs output to the core file. d. It directs output to the a.out file.

It is the "OR" operator

You use the same five shell functions every day and are looking for a way to ensure they are available as soon as you log into your account.What can you do? a. Make them residual system variables. b. Make them permanent environment variables. c. Load them via your login script. d. Make them permanent functions by adding them to the /func directory.

Load them via your login script

You've opened your mail on the company's server by using the mail command. Several messages are listed. How can you tell which ones are new or unopened messages? a. New messages begin with number 1 and unopened ones begin with the number 2. b. New or unopened messages begin with an N or a U. c. Both new and unopened messages begin with the tag,"unopened". d. New and unopened messages begin with a closed folder symbol.

New or unopened messages begin with an N or a U

When you create a section name in a man page, such as the DESCRIPTION sec- tion, what tag should you use just before the section name? a. .TH b. .SS c. \SC d. .SH

SH

Your network has a combination of Linux and Microsoft Windows computers. There is a Windows server that offers shared files for clients to access. Which of the following enables you to access the shared files from your Linux computer? a. Windows Share b. Network Share c. Samba d. Leopard

Samba

You are gathering information about the amount of disk space occupied by users' home directories. What command enables you to view a breakdown by individual directories under the /home directory?

The du command provides this information and there are a couple of ways to approach getting the information. One way is to use cd to change to the /home directory and then run a command like, du -h | more. Or from any directory you can run the command du -h /home | more.

What is an exit status and with what command is it used?

The exit status is used with the test command and is a value that represents the value of a test, such a value of 0 to show that the results of the test are true or a value of 1 to show the test results are false.

When you enter test -d tmp ; echo $?, you see a 0 displayed on the screen.What does this mean? a. The tmp file is empty. b. The tmp file contains over 1 MB. c. The tmp directory exists. d. The tmp directory is empty.

The tmp directory exists

What is the purpose of the top command and how can you use it to stop a process?

The top command enables the user to monitor CPU-intensive tasks. A process/task can be stopped when you enter the k command and provide the PID.

Your shell script, called .filetests, contains several functions used to run tests on files, such as to determine if a file is empty or has the correct permissions.Which of the following is/are true about .filetests? (Choose all that apply.) a. You can load the file's functions into memory by entering . .filetests. b. This is a hidden file. c. You can run the functions in the file by entering !. filetests. d. This is a character special file.

You can load the file's functions into memory by entering . .filetests. This is a hidden file.

Which of the following can you restore from a backup tape made via the dump command? (Choose all that apply.) a. a file b. a partition of directories and files c. a directory d. a subdirectory

a file a partition of directories and files a directory a subdirectory

Name two files that should be modified for security when using NFS

a. /etc/exports b. /etc/hosts.allow c. /etc/hosts.deny

Name two types of information that you can obtain using netstat.

a. Network protocol communications b. Network connections established by the host computer c. Network routing information d. Information about computers remotely logged onto the host computer e. Data and communications errors

You have a specialized data file, called customers, in which the fields in the file are separated by the character ^.You want to view this file with a colon between the fields before you convert it to remove the ^ characters and insert colons. Which of the following commands enables you to view the file in this way? a. insert -t : ^ | customers b. test - i [^] [:] customers c. cat customers | tr "^" ":" d. sub ':' '^' > customers

cat customers | tr "^" "."

Your company is launching a marketing campaign, and to start, you've created a file called promotion in normal uppercase and lowercase letters that will be used to place text for ads on the Internet and in newspapers.When you show the promotional text to your boss, she is curious about how it would look in all uppercase letters for emphasis.Which of the following commands enables you to convert the text and save the result to the file, promotion_uppercase? a. cat -u promotion | promotion_uppercase b. case [a-z] [A-Z] promotion >> promotion_uppercase c. case -u promotion > promotion_uppercase d. dd if=promotion of=promotion_uppercase conv=ucase

dd if=promotion of=promotion_uppercase conv=ucase

Which of the following are examples of symbols you might use in a flowchart? (Choose all that apply.) a. decision b. document c. data d. magnetic disk

decision document magnetic disk data

You've obtained over a hundred large graphics files to use in publications, but you want to be sure there is enough available disk space on your computer to store these files.Which of the following commands should you use? a. df b. diskfree c. ls --space d. netstat

df

You are working on a report about disk usage on your company's server to help determine if it is time to purchase additional disks. Which of the following commands enables you to obtain disk usage statistics for your report? a. free -t b. dd -of c. top -d | more d. du -h | more

du -h | more

You've purchased a new program for your computer, but the computer seems to slow down when you run the program. Which of the following commands enable you to monitor the memory usage as you run the program so you can determine if the program is a memory hog? a. free b. memuse c. mu d. test

free

Your colleague is creating a new man page to document a manufacturing process used by your company. She wants to be able to quickly view the man page as she works on it so that she can have other people view it before copying the man page into production.Which of the following commands enables her and others to peri- odically review her work in a format similar to the man page format? a. .// b. show c. groff d. dd

groff

A user on your network has received an error message that there is another com- puter on the same network using the same IP address, so the user cannot access the network.You send out a message to the 18 Linux users on your network to ask that they check the IP addresses on their computers and e-mail this information to you, so that you can determine who has the duplicate IP address.What utility do you tell users to run to determine their IP addresses? a. ifconfig b. ipquery c. df d. cmp

ifconfig

When working on the script in test -w clients, which of the following should you consider? a. output strength b. input validation c. functional reciprocation d. user vacillation

input validation

Which of the following commands enables you to stop the process ps a. bye b. kill c. ci d. tar

kill

You suspect that your computer's connection to the network is not working because you don't seem to be able to connect to the Internet through the network. Which of the following commands can help you determine if your connection is working? (Choose all that apply.) a. ping b. netconnect c. df d. tr

ping

You are setting up NFS to share files on the network from your Fedora Linux computer. Which of the following is a service that must be running to enable you to use NFS for sharing files? a. NFSstart b. share c. portmap d. netlink

portmap

What does a down arrow represent in a flowchart? a. process flow b. manual input c. stored data d. display

process flow

Your computer is slowing down because you've started a process that is taking most of the memory and CPU resources. Which of the following commands enables you to find the process id so you can stop that process? a. ps b. df c. du d. free

ps

Each month your business manually deletes specific records for employees who have left the company.You have been asked to write a script to automate this process. Which of the following commands works well for deleting records in a file? a. cut -a b. purge -d c. trdel -r d. sed -d

sed -d

What is the command that you can use (from root) to start the service in portmap? Question 14? a. service b. start c. init d. go

service

Create a statement that enables you to determine if the file /source/results is newer than the file /data/results.

stringtest() { test -z $text echo $? }

What symbol is typically used at the start and end of a flowchart? a. terminator b. display c. connector d. manual operation

terminator

Which of the following statements enables you to determine if the variable, called value, is less than 750? a. echo $value -l 750 b. comm value$ to 750 c. test $value - lt 750 d. test "value" >! 750

test $value - lt 750

The script you are creating takes data input to use for updating a file. Before taking the data input, you want the script to verify that the file to be updated, called clients, exists and that the script user has permission to write to that file.Which of the fol- lowing statements enables you to do this? a. string -w clients b. test -w clients c. chmod -all clients d. tr -ew clients

test -w clients

Create a simple function that determines if the string variable, text, contains no characters (is of zero length).

test/source/results -nt /data/results test/source/results -nt /data/results ; echo $?

You have a small network in your business with just a few network devices con- nected along with 22 Linux computers and you want to see how efficiently your network is designed.Which of the following commands can you use from different computers to determine the route information takes from one computer to another? a. vmstat b. pong c. nettraffic d. traceroute

traceroute

You help manage the Linux server for your department. Right now the server has no protection against power failures and there have been several power failures recently. To help make your case for a power protection device, you want to keep track of the amount of time the server has been running since the last power outage that caused it to go down. What command enables you to track how long the server has been up? a. top b. uptime c. df d. boot

uptime

How can you specify which device to use for a restore from a backup tape created by the dump command? a. Use the --device option. b. Use the parameter, output=devicename. c. Use the -f option. d. Use the -i option so that you can do the restore from the interactive mode and select the device on the fly.

use the -f option

You have obtained a new utility, called watchit, to monitor security on your computer, and you decide to run the utility in the background. Normally, to start the utility you would enter watchit at the command line. Which of the following commands enables you to start and run this utility in the background? a. hide watchit b. watchit& c. sh -h watchit d. shh watchit

watchit&

Which of the following script statements accomplishes the same thing as the statement: while [ "$part" != "alternator" ] ; do ? (Choose all that apply.) a. while $part <! "alternator" | do test b. while test $part != "alternator" ; do c. for test $part > "alternator" ; do d. test $part -eq "alternator" | do

while test $part != "alternator" ; do

You have recently met with your company's budget committee about creating a script to for producing the same budget reports at the end of each month. Because this is an important undertaking you've started by creating a flowchart.What step should you take next? a. Immediately write the functions you'll need for the script. b. Create a menu script. c. Find the three most important fields in the Budget file that you can use as keys d. Write pseudocode before you create the actual script.

write pseudocode before you create the actual script

When you create a shell function from the command line, what character do you enter at the first > prompt just after you declare the function's name? a. " b. { c. ' d. $

{


Ensembles d'études connexes

ATI Pharmacology Made Easy 4.0: The Reproductive & Genitourinary Systems

View Set

PP RNSG 1538 Intrapartum Mastery Quiz

View Set

Exam review insurance life and health missed questions:

View Set

Chapter 4 Adaptive Study Pre-Test

View Set