Table of Contents


Appendix B
UNIX EXERCISES

1.  About This Book
a.  What part of UNIX manages the computer system's resources?
b.  What function does the ksh perform?
c.  What 5 requirements do you need to fill before using UNIX?
2.  A Sample Session with UNIX User Commands
a.  Which command do you use to reset your "kill character" and "Backspace" keys?
b.  Name the three types of standard I/O.
c.  How do you return to your HOME directory?
d.  What keys abort a program?
e.  List 10 common commands in UNIX.
3.  System Overview
a.  What is the basic philosophy of the UNIX Operating System?
b.  What does multitasking mean?
c.  What does multiuser mean?
d.  What are four characteristics of the UNIX file system?
e.  What are the three types of files used in a UNIX file system?
f.  What two functions does the shell perform?
4.  alias/unalias
a.  What is the purpose of the alias command?
b.  What is the difference between csh and ksh aliasing command formats?
5.  apropos
a.  Why might you use the apropos command?
b.  Write the command to find information about line editors on UNIX.
6.  awk/nawk
a.  List three uses of the nawk program.
b.  List five features of nawk.
c.  What does the nawk '{ print }' file command do?
d.  Write a program to print a header, the /etc/group file, and a footer.
e.  How would you search for the pattern "tom" in the first field of input?
f.  What is the syntax for accessing the 10th element of an array named NAMES?
g.  Write the nawk script to display the first and fifth fields of the /etc/passwd file. Field one should be left justified in a 10-column output field. Field five should be left justified in a 40-column output field.
7.  banner
a.  What is the function of the banner command?
b.  What options are used with the banner command?
c.  What is one common use of the banner command?
8.  basename
a.  What functions are performed by the basename command?
b.  Why might you use the basename command in a shell script?
9.  bg
a.  What is the purpose of the bg command?
b.  Write the command to place job 2 into background processing.
10.  cal
a.  What does the cal command produce?
b.  What does the command cal 99 produce?
11.  calendar
a.  What service does the calendar command provide?
b.  List the date formats recognized by the calendar program.
c.  What does the - option cause to happen?
12.  cancel
a.  What two functions are performed by the cancel command?
b.  Why might you use the cancel command?
c.  Write the command line to cancel print job "imagen-915."
13.  cat
a.  List six uses of the cat command.
b.  How can you stop and start scrolling?
c.  Write the command to combine file1 and file2 into file3.
14.  cd
a.  What is the purpose of the cd command?
b.  Write the command to change directories to your parent directory.
c.  Write the command to return to the previous directory.
d.  Write the command to change to the user "njf" HOME directory.
15.  chfn
a.  Why might you use the chfn command?
b.  What information is changed by the command?
c.  Write the alternate format of the chfn command?
16.  chgrp
a.  What is the function of the chgrp command?
b.  Why might you use the chgrp command?
c.  Write the command to change all files in your HOME directory to the "mkt" group.
17.  chmod
a.  What is the purpose of the chmod command?
b.  Write the symbolic mode command to change the permissions on file1 to read and write for all users.
c.  Write the previous command using absolute modes.
18.  chown
a.  What is the function of the chown command?
b.  List two reasons for using the chown command.
c.  Write the command to change the ownership of the present working directory to "tina."
19.  clear
a.  What is the function of the clear command?
b.  Why might the clear command not work properly?
20.  cmp
a.  What is the purpose of the cmp command?
b.  What is the return code if the files are identical?
c.  Write the command to compare the standard input to file1.
21.  col
a.  What is the function of the col command?
b.  When might you use the col command?
c.  Write the command to use the col command with the cat file1 command.
22.  comm
a.  List three functions the comm command performs.
b.  Write the command to display the lines only found in the second file.
c.  Explain what text is displayed by the comm -3 file1 file2 command.
23.  Commands
a.  What is the format for a simple UNIX command?
b.  What signifies a parameter to be an option instead of an argument?
c.  What must precede an option or group of options?
d.  What does a dash preceded and followed by blanks signify to a command?
e.  What are the two types of commands in UNIX?
f.  What is the normal return code for a command that completed successfully?
24.  cp
a.  List the four uses of the cp command.
b.  Define source file and destination file.
c.  Explain the command cp file1 /etc/tty.
d.  Explain the command cp file1 file1.
25.  cpio
a.  What are the functions of the cpio command?
b.  What other UNIX command is often used with cpio when working with directory structures?
c.  Write the command to copy all of the files in your HOME directory to the /tmp directory.
26.  crontab
a.  What is the purpose of the crontab command?
b.  Write the cron command line to execute a command on Mondays and Fridays at 10:00 A.M., 2:00 P.M., and 4:00 P.M.
c.  Where is the standard output from your crontab commands sent if you do not redirect it?
d.  Write the commands required to create a crontab file and place it in the cron directory.
27.  crypt
a.  What is the function of the crypt command?
b.  Can "root" (the super-user) read your encrypted file?
c.  Write the command to encrypt file1. You want to be prompted for the encryption key.
28.  csplit
a.  What does the csplit command do?
b.  What are the uses of the csplit command?
c.  Write the command to split file1 at each occurrence of " (.*)."
29.  cut
a.  What two modes of cutting are performed by cut?
b.  Write the command to cut fields 1 and 5 from the /etc/passwd file.
c.  What causes the error message "line too long" to be displayed?
30.  date
a.  Can you (a normal user) change the system date?
b.  What is the default output format of the date command?
c.  How do you display only the hours and minutes? (SV only)
31.  dd
a.  What are the two main functions of the dd command?
b.  List five types of conversions the dd command performs.
c.  Write the command to convert ASCII input to EBCDIC output.
32.  df
a.  What is the purpose of the df command?
b.  Write the command to display only the /usr filesystem information.
33.  diff
a.  What does the diff command do?
b.  How do you make diff ignore blanks in the input?
c.  Explain the command diff - file2.
34.  dircmp
a.  What is the function of the dircmp command?
b.  Explain the output of the first listing generated by dircmp.
c.  What command makes the output listings easier to read on your screen?
35.  dirname
a.  What is the purpose of the dirname command?
b.  When might you use the dirname command?
36.  dirs
a.  What does the dirs command display?
b.  Which shell supports the dirs command?
c.  What command must be used before the dirs command becomes useful?
37.  du
a.  What is the purpose of the du command?
b.  How do you display only the summary for all files and directories in your present working directory?
38.  echo
a.  What are 5 uses of the echo command?
b.  Does the BSD version support escape sequences?
c.  What is equivalent to the -n option on the System V version?
39.  ed
a.  How does ed differ from a full screen editor like vi?
b.  Write the command to edit/create file myfile.
c.  What are the two modes of operation within ed?
d.  What is a regular expression?
e.  Write the global search command to locate all empty lines and display the line number.
f.  How do you enter text into myfile?
g.  How do you return to the ed prompt from insert mode?
h.  How do you display all lines within the buffer?
40.  egrep
a.  What is the function of the egrep command?
b.  In what situation will a given pattern not be located?
c.  How do you display lines that do not match the given string?
41.  env
a.  What are the two purposes of the env command?
b.  What happens if no arguments are given on the env command line?
c.  Write the command to start a new sh without passing the current environment.
42.  eval
a.  What does the eval command force the shell to do?
b.  Explain the command eval echo '$'$X, where X=FILE.
43.  ex
a.  What is the function of the ex command?
b.  How do enter full screen mode?
c.  How do you return to ex mode to perform multiple commands?
d.  Write the command to mark a position in the buffer as mark "a."
e.  What address command returns you to mark "a"?
f.  Write the command to change all occurrences of "form" to "from" and have the editor request confirmation before making the change.
g.  Explain the command !$sort -u, assuming you are on the first line of the buffer.
h.  How do you write the current line to a file named "hold.one"?
44.  exec
a.  What are the purposes of the exec command?
b.  Write the command to overlay the current shell with the csh.
45.  exit/logout
a.  What does the exit command do?
b.  What keystroke performs the same function?
c.  What does logout do that exit does not?
46.  expand/unexpand
a.  Explain the expand command.
b.  How do you convert tabs to only four spaces?
47.  export
a.  What is the purpose of the export command?
b.  What does the export command do if you run it without arguments?
c.  Why is the export command important?
48.  expr
a.  What are the four types of operations handled by expr?
b.  Write the command to delete the first letter from the value of $X.
c.  Write the command to return the length of a string in $STR.
d.  What commands in the ksh have replaced the expr command?
49.  false
a.  What is the function of the false command?
b.  What is the return code of the false command?
50.  fc/!
a.  Describe three uses of the fc command.
b.  What happens when you press Escape and type a v?
c.  How do you execute the last command that began with "ls"?
d.  What does the !! command do?
e.  Write the command to execute the last command that started with "vi."
51.  fg
a.  What is the purpose of the fg command?
b.  Which shells and operating systems support the fg command?
c.  Write the command to bring job 3 to the foreground.
52.  fgrep
a.  Why might you use the fgrep command instead of grep?
b.  How do you search for uppercase and lowercase letters simultaneously?
c.  What option prevents diagnostic messages from being displayed?
53.  file
a.  What does the file command do?
b.  What type of data within files may confuse the file command?
c.  Why might you use the file command?
54.  Filenames and Filename Generation
a.  List five de facto standard filename extensions.
b.  Why would you not want to use the ">" character in a filename?
c.  What are some of the files matched by the filename notation "?ite"?
d.  Why are you unable to use the "/" character within a filename?
e.  How do you perform filename completion using the ksh?
f.  How do you perform filename completion using the csh?
55.  find
a.  What does the find command do?
b.  Write the command to display all the files in your HOME directory and all subdirectories.
c.  Write the command to remove all files which have not been modified in 30 days, starting at the current directory.
56.  finger
a.  What default information is displayed by the finger command?
b.  What information is placed in the .project file?
57.  fmt
a.  What function does the fmt command perform?
b.  Write the command to format file1.
c.  Write the command to format the next paragraph inside vi.
58.  fold
a.  What does the fold command do?
b.  Describe some uses of the fold command.
59.  getopts
a.  What is the purpose of the getopts command?
b.  What are valid options for getopts -x:?
c.  If an argument is required after an option, where is the argument stored?
60.  grep
a.  What does the grep command do?
b.  What does the name "grep" mean?
c.  Write the command to locate all lines beginning with "r" in the /etc/passwd file.
61.  groups
a.  What does the groups command do?
b.  Explain the difference between your primary group and secondary groups.
62.  hash
a.  What is the purpose of the hash command?
b.  Can the hashing function be automatic; if so how?
63.  head
a.  What is the function of the head command?
b.  Why might you want to use it?
c.  What does the command head +25 afile do?
64.  history
a.  What specific file does the history command display?
b.  How do you control the number of commands stored in the history file for the ksh?
c.  How do your change the history character to a "." from "!" in the csh?
65.  hostname
a.  What does the hostname command do?
b.  What are some uses of the hostname command?
66.  id
a.  What information is displayed by the id command?
67.  Input/Output and Redirection
a.  What are the three standard types of I/O?
b.  Write the command to force the standard error onto the standard output, for ksh and csh.
c.  How do you assure input is read from your keyboard by the ksh's read command?
d.  Write the command to redirect the standard output to file $X.
68.  jobs
a.  Which shells support the jobs command?
b.  What is the purpose of the jobs command?
69.  join
a.  What is the function of the join command?
b.  Write the command to join file1 and file2 on key column 3.
70.  kill
a.  What does the kill command do?
b.  What command is often used to provide PID information so you can use the kill command?
c.  Why might you use the kill command?
71.  ksh/csh/sh
a.  What two major functions does the Korn shell provide?
b.  List 7 enhancments the ksh provides that the sh does not.
c.  Which option automatically exports variables when they are assigned a value?
d.  Which option might you use to debug a shell script?
e.  What character would you use to separate three commands on the same line?
f.  What character starts a comment in a shell script?
g.  Which directory does the ~jim notation reference?
h.  What is the output of the echo 'My shell is $SHELL' command?
i.  How do you enter "In-line Editing mode" (assume you have EDITOR=vi)?
j.  Explain the difference between the . myscript and myscript commands.
72.  leave
a.  What function does the leave command perform?
b.  When might you use it?
73.  let
a.  What is an alternate syntax format to the let command?
b.  Write the command to display the result of 1024 times 100, for the ksh and the csh.
c.  Which command does the let command replace?
74.  line
a.  What does the line command do?
75.  listusers
a.  What information is displayed by the listusers command?
76.  ln
a.  What is the purpose of the ln command?
b.  Write the command to link file to filex.
77.  login
a.  Why does the login command exist?
78.  logname
a.  What does the logname command do?
79.  lp
a.  What is the function of the lp command?
b.  How do you suppress the request information message?
c.  Write the command to print the /etc/group file to the lzr printer.
80.  lpq
a.  Why might you use the lpq command?
b.  Write the command to display information about the imagen printer.
81.  lpr
a.  What does the lpr command do?
b.  Write the command to print file1 to the hplj printer.
82.  lprm
a.  What is the purpose of the lprm command?
b.  Write the command to remove print job 1362.
83.  lpstat
a.  What information does the lpstat command provide?
b.  Write the command to display all information about the spooler.
84.  ls
a.  What function does the ls command serve?
b.  Write the command to display all files in all subdirectories.
c.  Write the command to display nonprintable characters.
d.  Explain each position of the file modes.
e.  Write the command to allow other users to execute a program as though they owned the program.
85.  machid
a.  What is the function of the machid commands?
b.  Why might you use these commands?
86.  mail/mailx
a.  What is the purpose of the mail/mailx command?
b.  What is the format of the mailx command to send mail to a user?
c.  What is the format for reading mail from your mbox file?
d.  How do you edit a message you are sending?
e.  When reading mail how do you display the next page of header lines?
f.  When reading mail how do you delete messages 20 through 34?
g.  Write the internal command to send message 5 to the dp printer.
87.  man
a.  What does the man command do?
b.  Type the command to display information about the vi command.
c.  On BSD what command searches man headers for matching words?
88.  mesg
a.  What is the purpose of the mesg command?
b.  Write the command to prevent messages?
89.  mkdir
a.  Explain why or why not the command mkdir src/cmd src works.
b.  What does the SV -m option do?
c.  On SV how can you make the command in a. work?
90.  more/page
a.  What is the purpose of the more command?
b.  When might you want to use more?
c.  Write the internal command to find the first occurrence of "string" in the current text of more input.
d.  How do you scroll down the input?
91.  mv
a.  What are three uses of the mv command?
b.  What two commands does the mv command use to perform its job?
c.  Write the command to rename ../file1 to src/myprog.c.
92.  newgrp
a.  Describe the function of the newgrp command.
b.  Why would you use the newgrp command?
93.  news
a.  What does the news command do?
b.  How do you force all news items to be displayed?
94.  nice
a.  What does the nice command change?
b.  What are some uses of the nice command?
95.  nl
a.  Describe the function of the nl command.
b.  Write the command to number lines in increments of 10 and zero fill five spaces.
96.  nohup
a.  What is the purpose of the nohup command?
b.  Where is the output of the nohup command written?
c.  Can you redirect the output to a file?
97.  od
a.  What formats of output data does the od command support?
b.  What does the -c option do?
c.  How do you display data in hexidecimal format?
98.  pack/unpack
a.  What does the pack command do?
b.  How do you reverse the effects of the pack command?
c.  Do you have to specify the .z extension when unpacking a file?
99.  Parameters/Variables/Arrays
a.  What is the shell "environment"?
b.  How can you set positional parameters from within a shell?
c.  Which variable contains the return status of the last command?
d.  Write the command for assigning "Subscript 100" to the 100th position of the array ex_array.
e.  What is the syntax for referencing positional parameter 23?
f.  Name one situation where using an array would be better than using variables.
100.  passwd
a.  Explain password aging.
b.  What are the requirements of SV passwords?
c.  What are two reasons for using the passwd command?
101.  paste
a.  List the functions of the paste command.
b.  Write the command to display the standard input as 5 columns.
102.  pcat
a.  When do you use the pcat command?
b.  What extension must the file have to use pcat?
103.  pg
a.  List some of the features of the pg command?
b.  What does the -n option do?
c.  Write the command to reset the pg prompt to "Press CR to continue."
d.  How do you search for a string from the command line?
e.  What types of commands are supported by pg?
f.  How do you search backward from the pg prompt?
g.  Write the command to skip forward 3 files.
104.  popd
a.  Explain what the popd command does.
b.  Which command must be used before popd can be used?
105.  pr
a.  What is the function of the pr command?
b.  Write the command to convert input tabs to 4 spaces.
c.  How do you double space the output using pr?
d.  Write the command to change the header to "My test pr command."
e.  Generate a listing of files in 3-column output using just pr.
106.  print
a.  Explain the two different print commands.
b.  Write two versions of print that do not print a new-line.
c.  How do you save the output of the print command to the history file?
107.  printenv
a.  What is the purpose of the printenv command?
b.  When might you use the printenv command?
108.  Programming Constructs - Shell Programming
a.  List the steps you follow to create a shell script.
b.  Change the lg shell script to display the information field of the /etc/passwd file. The information field is field 5.
c.  List the three types of looping conventions supported by the shells.
d.  Why use the case statement instead of the if statement?
e.  What are the benefits of using functions?
109.  ps
a.  What is the function of the ps command?
b.  If the output is greater than 132 columns, what option do you use to display it correctly?
c.  How do display information about all processes on SV and or BSD?
110.  pushd
a.  Explain the directory stack.
b.  Why do you use the directory stack?
111.  pwd
a.  What does the pwd command do?
b.  Why use the pwd command?
112.  read/readonly/set $<
a.  What does the read command do with the input it reads?
b.  What does the readonly command do that read does not?
c.  If you have a command read X Y and your input is "INPUT HERE," what is the value of Y?
113.  Regular Expressions (REs)
a.  Explain a regular expression.
b.  Why are they so valuable?
c.  Write the regular expression to match multiple occurrences of the same character.
d.  How do you reference regular expressions that have been grouped?
114.  rm
a.  What function does the rm command perform?
b.  Why might you use the rm command?
c.  How do you remove directories with the rm command?
115.  rmdir
a.  What condition must the directory be in before rmdir will work?
b.  Explain the -p option on SV rmdir.
116.  script
a.  What is the purpose of the script command?
b.  What file does the script file create by default?
117.  sed
a.  What is sed?
b.  Explain how it basically works.
c.  Write the command to subsitute all occurrences of "system" with "computer."
d.  Which commands allow you to insert text?
e.  Write a sed command to display the first 100 lines of a file.
118.  set/unset
a.  What functions does the ksh and sh set command provide?
b.  What does the csh set command do?
c.  How do you display the local environment using set (ksh and sh)?
d.  Write the csh command to set TERM to vt100.
119.  setenv/unsetenv
a.  What does the setenv command do with variables?
b.  Can a child process change the environment of a parent process?
c.  How could you pass a variable's value to a parent shell?
120.  shift
a.  What does the shift command do?
b.  Write the command to shift all but one parameters (hint: use the eval command).
121.  sleep
a.  Explain the sleep command.
122.  sort
a.  What type of files does the sort command sort?
b.  Write the command to sort on field 5.
c.  How do you sort numbers?
d.  Can sort reverse the order of the sort?
e.  How do you remove duplicate adjacent lines?
123.  spell
a.  How can you use your own list of correctly spelled words?
b.  What are the shortcomings of the spell command?
124.  split
a.  Explain how the split command functions.
b.  Write the command to split myfile into 10 line files whose names begin with mysplit.
125.  stop
a.  What does the stop command do?
b.  What state must a process be in before you can use the stop command on the process?
c.  How does the ksh implement the stop command?
126.  stty
a.  What is the purpose of the stty command?
b.  Write the SV and BSD command to display all settings.
c.  Write the command to change your erase key to Ctrl-B and your kill key to Ctrl-K.
d.  What happens if you type the stty -echo command?
e.  What happens if you disable isig (stty -isig)?
f.  What is the default EOF character for stty (UNIX)?
127.  su
a.  What is the function of the su command?
b.  Explain what happens if you don't use the - option.
c.  Why might you use the su command?
128.  sum
a.  List some uses of the sum command.
129.  suspend
a.  What is the purpose of the suspend command?
b.  What is the format of the suspend command?
c.  How do you restart a suspended job?
130.  tabs
a.  Explain what the tabs command does.
b.  What is meant by "canned" tab formats?
c.  Why must tabs know your terminal type?
131.  tail
a.  What is the purpose of the tail command?
b.  What does the -f option cause tail to do?
c.  Write the command to skip the first 25 lines of myfile.
132.  talk
a.  Describe the talk command.
b.  Write the command to talk to john at utvax.
133.  tar
a.  What is the function of the tar command?
b.  Why might you use the tar command?
c.  Write the command to tar your current directory to /dev/rmt/0m.
134.  tee
a.  What is the function of the tee command?
b.  What does the -a option do?
c.  What is the name of the output files from tee?
135.  test
a.  Explain the function of the test command.
b.  Write the command to compare two numbers, $X and $Y.
c.  Write the command to find out if a file is readable and writable.
136.  time/timex
a.  What is the function of the timex command?
137.  time/times
a.  What is the purpose of the times command?
b.  Explain how the time command functions.
138.  touch
a.  What is the function of the touch command?
b.  What is the difference between the SV and BSD touch commands?
c.  Write the command (SV) to create a file with the date of Nov 11, 1989 at 12:00 noon.
139.  tput
a.  What does the tput command do?
b.  Write the command to clear your terminal screen.
c.  Write the command to move your cursor to position 10 20 on your screen.
140.  tr
a.  What is the function of the tr command?
b.  Write the command to translate all numbers to dashes.
141.  trap/onintr
a.  Explain what the trap command does.
b.  Write the trap command to rm all files in /tmp with names ending in .$$ if you press the Delete key (Signal 2).
142.  true
a.  What is the function of the true command?
b.  What is the return code of the true command?
143.  tset
a.  Explain what the tset command does.
b.  Write the command using tset to set your erase key to Ctrl-H and set your terminal type to vt100 if you're on a tty with a baud rate higher than or equal to 9600.
c.  What file might you place the tset command in for regular use?
144.  tty
a.  What information does the tty command display?
b.  When might you use the tty command?
145.  typeset
a.  What does the typeset command allow you to do with shell variables?
b.  Write the command to display a variable with 5 positions and zero filled.
c.  What does the -l option cause typeset to do?
146.  ulimit/limit
a.  What does ulimit limit?
b.  What does the limit command limit?
c.  How can you as a user reset your ulimit to a higher value?
147.  umask
a.  Explain the function of the umask command.
b.  What does the umask 023 command force for permissions on newly created files?
148.  uname
a.  What information is displayed by the uname command?
149.  uniq
a.  What function is performed by the uniq command?
b.  How do you display only uniq lines?
c.  Write the command to compare only columns 20 and higher.
150.  users
a.  What information is displayed by the users command?
b.  Why would you use the users command?
151.  vi/view
a.  What is vi?
b.  What must you do before using vi?
c.  How do you start vi and have it position you at a certain string in the file?
d.  What are the six operators used by vi?
e.  How do you recover a file using vi?
f.  What are the modes within vi?
g.  Explain what a register is in vi.
h.  Describe how to copy text between two buffers.
i.  How do you move to the top line of the buffer?
j.  Write the command to filter the entire buffer through the sort -u command.
k.  How do you mark an address and how do you reference the marked address?
l.  Create a string macro to write the current file to disk and edit the next file in the argument list.
152.  wait
a.  What function does the wait command serve?
b.  When do you use it?
153.  wall
a.  What does the wall command do?
b.  When is it often used?
c.  Who usually uses the wall command?
154.  wc
a.  What units are displayed by the wc command?
b.  Write the command to count the number of characters in all files beginning with a "f."
155.  whatis
a.  Why would you use the whatis command?
b.  Is the information displayed always decisive and helpful?
156.  whence/type
a.  Explain the function of the whence command.
b.  Why do we need the whence command?
157.  whereis
a.  What information does the whereis command display?
b.  How do you force whereis to only search for man page entries?
c.  Can you change the directories whereis searches? If so, how?
158.  which
a.  What is the function of the which command?
b.  What does the which command display if the command is not located?
159.  who
a.  What is the function of the who command?
b.  How many options does the BSD version support?
c.  What does the -u option do?
d.  How can you display the number of users currently on the system?
160.  whoami
a.  What information does the whoami command display?
161.  write
a.  What does the write command do?
b.  How do you terminate the write command to send the message?


Table of Contents