Chapters 4&5
Home Up Errata / Updates Why Shell? Using Telnet Telnet Logging Chapters 1&2 Chapters 3&7&13 Chapters 4&5 Chapters 6&8 Chapter 22 Chapter 23 Chapters 10&12 Chapter 14 Chapter 15
Updated:
2000-10-20 16:25

Chapters 4&5 Exercises

Read Chapters 4 and 5 of the Unix text and work on the Unix system. Make sure you can answer the following questions:

Chapter 4     UNIX Directories

 (Pages 242-298)

4-1     When you first log on a UNIX system, you are automatically placed in your home directory. Explain what is a home directory (p.22) and which environment variable contains the full, absolute pathname of your home directory.

4-2     What is an inode number?  What do inode numbers have to do with your home directory?

4-3     What command must you issue to arrange that the Korn shell displays your home directory as the shell prompt? What command would you use to display your current working directory as the shell prompt?

4-4     What does mkdir stand for? cd? pwd? rmdir?

4-5     What is the quickest way to get back to your home directory if you are currently at /tmp/X11/lost&found/cyberville/oz?

4-6     If you are at /tmp/X11/lost&found/cyberville/oz and wish to list the names of files in your home directory without losing your hard-to-come-by current directory, what would you do? Among the all possible ways to do it, which one is the simplest?

4-7     Name a command that will create an empty file quickly. (p.255)

4-8     Explain any possible differences between the following commands

             cp file1 file2 file3
             cp file1 file2 file3/.

4-9     Explain the differences among the following commands:

              cd .           cd ../..
              cd ..          cd ../../..
              cd /           cd ~/..
              cd ~           cd ~/../..

4-10     Under what circumstances can you have two files or directories with the same name?

4-11     Your friend's userid is abcd0001, Explain what would happen if you issue:
              ls ~abcd0001

4-12     Why is that "ls ~root" works, but, "ls ~/tmp" does not work? (p.274-5)

4-13     Explain the options -a, -l, -i, and -F of the ls command.

4-14     You want to arrange that one of your files appears in three other directories without physically recreating or recopying the program file three times. (Having three different copies of the information would make it hard to update.)  Explain how would have the same file content appear in three directories without making three copies of the file.

4-15     All files have inode numbers.  Do directories have inode numbers? Do linked files have inode numbers? What is special about the inode numbers of linked files?

4-16     How can you arrange that the system delete a file, if the file has several links?

4-17     Explain the differences between "rmdir" and "rm -r".

4-18     Give the command that will list all files that belong to you in the /usr/tmp directory.

4-19     Give the command that will list all files named core in the entire Unix system.

4-20     Give the command that will create a new file called myfiles containing the name of all files owned by you on the system.

Chapter 5     The Shells

5-1     What is the core program of a UNIX system? What are its functions?

5-2     How does the shell interact with users and the core program?

5-3     What is a token on a command line? Name all the shell's token delimiters that you have learned.

5-4     What character to the shell serves as an in-line Return (new line) key to separate commands?

5-5     Where on command lines does the shell search for utilities (command names)?  Name as many places as you can.

5-6     Enter this command pipeline:      sort | grep aaa | tee bb | wc

Suspend the job by entering CTRL-Z and then issue ps.  How many processes are you running?  Name all the processes and their process IDs (pids).  How can you resume the suspended job (bring it into the foreground again)?

5-7     Given the command:           ls   -l   practice
              -l is interpreted by the shell as a(n) _______________,
              -l is interpreted by the utility ls as a(n) _____________,
              practice is interpreted by the shell as a(n) ____________,
              practice is interpreted by the utility ls as a(n) _____________.

5-8     Given the command:           wc   -wc   wc
              The first wc is interpreted by the shell as a(n) ______________,
              The second token -wc is interpreted by the shell as a(n) ________________,
              The third token wc is interpreted by the shell as a(n) ________________,
              The second token -wc is interpreted by the utility wc as __________________,
              The third token wc is interpreted by the utility wc as a(n) ________________.

5-9     Explain the different output results of the following two commands (noclobber is off):
              sort   pract-2   > pract-2
              sort   -o   pract-2   pract-2

5-10     > is redirecting the output to the right. | is piping the output to the right.
              What does the combined >| mean to the shell?

5-11     What are the differences between the commands set and env in the Korn shell?

5-12     Explain how to make a local variable appear in the environment in the Korn shell, so that the variable will be passed to sub-shells and other processes started by that shell.

5-13     Explain how to remove a local variable from the Korn shell.

5-14     Give and then explain the output of the command:

              echo ' $USER ' $USER "$USER" ' "$USER" ' " '$USER' " \$USER

 5-15     What is the special variable $0 (0 as zero) referring to if it exists in a script file?  (Modify any script file you have written and add the line "echo It is $0" to the script.  Run the script.  What does $0 stand for?)

5-16     Give the command that will append the "current directory" to the paths listed in your PATH environment variable.  Why is having the current directory in your PATH a security risk on a multi-user Unix system?

5-17     What are the differences in output between the commands "ls *" and "echo *"?  (Hint: Consider what happens if the current directory contains sub-directories.)

5-18     You want to find all records containing the string happy in files in the current directory whose names begin with snow followed by some character followed by one digit among (0,1,2,3) followed by one other digit (3,4,5,6,7, or 8) followed by zero or more characters. State the shortest command to find these records.

These exercises were originally created by Maitang Mark

Web Author: Ian! D. Allen idallen@ncf.ca
Updated: 2000-10-20 16:25