CSCI 3190 (Directed Study (Unix Power Tools)), Spring 2004:
Homework 3

Assigned:
February 11, 2004.

Due:
February 16, 2004, at 5pm.

Credit:
10 points.

Reading

Read about the following topics, either by skimming the mentioned online references or in another book or reference.

  1. Shell customization (aliases, functions, more environment variables, how/where to save these for future sessions). Partly covered in section 7.4 of Introduction to Linux. Covered in more detail in sections 3 and 6 of the GNU Bash Reference Manual.

  2. Pipes and filters. Covered in section 5 of Introduction to Linux.

  3. Some filters and other (allegedly) useful commands. Skim the man and/or info pages for the following commands to see what they do, or skim the shorter discussion in one person's ``Useful UNIX Commands'' list:

    cat, echo, less, more, head, tail, sort, uniq, grep, wc, cut, paste, tr, expand, awk, sed, find, csplit.

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.

Shell Customization

  1. (2 points) Traditionally Unix sorted filenames in a case-sensitive way (i.e., Zee would come before aFile). The default for many current systems is to sort in case-insensitive order and ignoring punctuation. This behavior is controlled by the environment variable LANG. How do you find out what the current setting of this variable is? How would you change it to something else, for the current session? What would you do to change it for future sessions as well?

    (To see how this variable affects things, compare the output of ls -a with LANG set to en_US and with LANG set to C.)

    Note: If you use a shell other than bash, either answer for bash or tell me what shell you use.

  2. (2 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.)

    (Whether these should be aliases or shell functions is your choice. 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.

Pipes, Filters, and Other Useful Commands

  1. (2 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.)

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

  3. (2 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? (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
2004-02-13