Book: LPI Linux Certification in a Nutshell Section: Chapter 8. Exam 101 Review Questions and Exercises
1. ### 8.1 GNU and Unix Commands (Topic 1.3) #### 8.1.1 Review questions Describe the difference between shell variables and environment variables. Compare and contrast built-in and explicitly defined commands and those found in `PATH`. After a lengthy session of file manipulation on the command line, what will the !ls command produce? What program was the source for the default history editing key bindings in bash? Explain the notion of pipes as they refer to shell capabilities, and illustrate using an example of two or more filter programs. Explain the -p option to cp and give an example of why it is necessary. Give two examples of files matched by the wildcard `??[!1-5]`. Name the three Standard I/O streams and their functions. Give an example of the redirection operator, `>`, and describe how the outcome would be different using the `>>` operator. What process is the ultimate ancestor of all system processes? Give both the PID and the program name. Name three common utilities used for process monitoring. What happens to a typical daemon when it receives `SIGHUP`? How would the behavior be different if it received `SIGKILL`? Compare and contrast background and foreground jobs, and state the syntax to put a command in the background on the command line. Explain the relationship between a process' nice number and its execution priority. What two classifications of characters make up regular expressions? How are the regular expressions `[A-Z]*` and `^[A-Z]*$` different? #### 8.1.2 Exercises ##### 8.1.2.1 Exercise 1.3-1. Bash Start a bash shell in a console or terminal window and enter the following commands:
       $ MYVAR1="Happy"
       $ MYVAR2="Birthday"
       $ export MYVAR1
       $ bash
       $ echo $MYVAR1 $MYVAR2
       $ exit
       $ echo $MYVAR1 $MYVAR2
2. 3. Was the behavior of the two echo commands identical? If so, why? If not, why not? What happened immediately after the bash command? Which variable is an environment variable? Continuing the previous exercise, enter Ctrl-P until you see the last echo command. Enter Ctrl-P again. What do you see? Why wasn't it the exit command? Enter Ctrl-P again so that the export command is displayed. Add a space and `MYVAR2` so that the line now looks like this:
          $ export MYVAR1 MYVAR2
4. What happens when you enter this command? Still continuing the previous exercise, enter the command !echo. Does anything change as a result of the revised export command? The file command is used to examine a file's contents and displays the file type. Explain the result of using file as follows:
       $ cd / ; file $(ls | head -10)
1. ##### 8.1.2.2 Exercise 1.3-2. GNU commands in pipes Execute this command on your system:
       $ cut -d: -f1 /etc/passwd | fmt -w 20 | head -1
2. What was displayed? How many lines of output did you see? Why? What was the width of the output? Why? Execute the following sed substitution command and explain why it might be used on /etc/passwd:
       $ sed 's/:[^:]*:/:---:/' /etc/passwd | less
1. ##### 8.1.2.3 Exercise 1.3-3. File management Execute this command:
       $ cd /sbin ; ls -li e2fsck fsck.ext2
2. What is the significance of the first field of the output? Why is it identical for both listings? Why are the file sizes identical? Execute the following command sequence and explain the result at each step (this example assumes that cp is not aliased to cp -i, which is a common default alias):
       $ cd
       $ cp /etc/skel .
       $ cp -r /etc/skel .
       $ cp -rfv /etc/skel .
       $ cp -rfvp /etc/skel .
1. Remove the directory created in the previous exercise, using rmdir and/or rm. Which command can complete the task in a single step? Explain when the wildcard `{htm,html}` might be useful. Give an example of how the wildcard `*.[Tt][Xx][Tt]` could be used with directory listings. What can be said about filenames matched by the `*.?` wildcard? ##### 8.1.2.4 Exercise 1.3-4. Redirection Experiment with redirecting the output of ls as follows:
       $ cp /etc/skel . 2> info.txt
2. How is the terminal output different than that observed in Exercise 1.3-3? What is written to info.txt ? Experiment with the various forms of redirection in Table 3-4, including the tee command. ##### 8.1.2.5 Exercise 1.3-5. Processes Experiment with ps, pstree, and top to monitor active processes on your system. Include top's interactive commands. If you have Apache running, use ps (and perhaps grep) to identify the httpd process and its pid, which is owned by root. Send that process the `HUP` signal as follows:
       $ kill -SIGHUP pid
   Using tail, examine the Apache error log (the location of your log file may differ):
       $ tail /var/log/httpd/error_log
3. What was the effect of `HUP` on Apache? While running X, start some interactive processes in the background and experiment with using jobs, bg, and fg. For example:
       $ netscape &
       $ xterm &
       $ emacs &
       $ jobs
       $ fg 1
       $ fg 2
       ...
1. 1. Were you able to bring each of the jobs to the foreground successfully? ##### 8.1.2.6 Exercise 1.3-6. Process priority This exercise starts a process, using various methods to view and modify the process execution priority: Start an editing session in the background using nice:
          $ nice vi &
   2. Observe that the process was nice'd using ps:
          $ ps -u
   3. Check it again using top:
          $ top -i
1. Within top, renice the vi process using the r command and observe the effect on priority. Exit top and use renice to set the nice value back to zero. ##### 8.1.2.7 Exercise 1.3-7. Regular expressions Use a simple regular expression with grep to find sh and bash users in /etc/passwd:
       $ grep "/bin/..sh" /etc/passwd
2. Determine the number of empty lines in /etc/inittab :
       $ grep "^ *$" /etc/inittab | wc -l
Explain the regular expression and the use of wc.