CSCI 3294 (Unix Power Tools), Spring 2005:
Homework 2

Assigned:
March 21, 2005.

Due:
March 28, 2005, at 5pm.

Credit:
40 points.

Reading

Read about the following topics in the list of suggested readings, either in one of the suggested readings or in another book or reference. (These are the last two topics for February 7 and the first topic for February 21, reordered.)

(Notice that questions below are grouped by topic, so you can read about one topic, do the related questions, and then move on to the next topic.)

Problems

Answer the following questions. You may write out your answers by hand or using a word processor or other program, but please submit hard copy, either in class or in my mailbox in the department office. Answers to most questions will involve experimentation on a UNIX or Linux system. You are free to use any appropriate system; if you use something other than Red Hat Linux please tell me what.

Filter programs and other useful commands

  1. (5 points) Suppose you have a directory program1 containing many source code files you copied from your instructor and then modified. If the instructor's files are in ~theprof/csci1321/program1), what would you type at the command line to find out how your code differs from your instructor's? (Hint: You can do this with one command.)

  2. (5 points) What would you type at the command line to find all files in your home directory (and all subdirectories) that are more than a week old and end with .bak?

Shell basics and customizations

  1. (5 points) When you type a command (e.g., ls), the shell has to find an executable (program) to run. Where does it look? How could you make it also look in your directory MyPrograms? (Your solution can be one that only applies to the current session, i.e., until you log out.)

  2. (5 points) Give the command(s) you would use to define two aliases or shell functions: delete to move a file to be ``deleted'' to a temporary directory such as $HOME/.trash, and undelete to move a ``deleted'' file from the temporary directory to the current directory. (Examples of use: delete myfile, undelete otherfile.)

    (It's up to you to decide whether these should be aliases or shell functions. You might be constrained by the capabilities of aliases versus functions. If you use a shell other than bash, either answer for bash or tell me what shell you use.)

    Notice that commands to define aliases or functions can be entered from the command line, in which case they apply to the current session only, or can be included in an appropriate initialization file.

I/O redirection and pipes

  1. (5 points) How would you invoke the g++ compiler if you want to be able to page through its output (both standard output and standard error) with less? How would you capture the error output in a file called gcc-ERRORS?

  2. (5 points) How could you make a one-line text file without using a text editor? Could you extend this idea to make a multiline text file? Tell me about as many ways to do this as you can think of.

  3. (5 points) What would you type at the command line to get a sorted list, with no duplicates, of all the users logged into the local network? (Hint: The command rwho may be useful. Its output on the lab machines is not as meaningful as one might like because apparently sometimes it still thinks people are logged in when they're not. Don't worry about that; answer as you would if its output were perfect.)

  4. (5 points) Answer/do one of the following:

    1. What would you type at the command line to find out how many lines total are contained in all the files ending in .c in the current directory, printing only the total number of lines? You decide whether to include files in subdirectories or only those immediately in the current directory. (Hint: apropos lines might be helpful if the right command(s) don't immediately occur to you.)

    2. Describe something you actually want to do (e.g., archive all files that have been changed in the last 24 hours, find a Janus machine that's up and connect to it with ssh) and a solution involving a pipe and at least one of the commands mentioned in the reading for this assignment.



Berna Massingill
2005-04-22