Prev Up Next
Go backward to 4.7 grep and regular expressions
Go up to 4 Labs
Go forward to 4.9 Three tcsh scripts

4.8 Shell script -- dir

Using a text editor, create a shell program. Your shell program will probably need to use cut, ls, expr, grep, paste, wc, cat, hostname, and cal. It will probably also use pipes, redirection, variables, and command substitution.

Your program should do the following:

  1. "Display" the number of days in the current month. For example:
    September 1996 has 30 days
    
  2. "Display" the number of directories in the root directory. For example:
    The root directory on gort has 12 directories
    
  3. "Display" the root directory in the following format. This is what the ls -l / command gives:
    drwxr-xr-x  2 root    2048 Jun 30 14:26 bin
    drwxr-xr-x  2 root     512 Jun  2 15:59 bsd-src
    -rw-r--r--  1 root  147456 Sep  7 14:25 core
    -rw-r--r--  1 root     925 Apr  8 18:00 dflt.DECterm
    drwxr-xr-x  3 root    3072 Sep  8 14:45 dev
    drwxr-xr-x  6 root    6656 Sep  9 22:25 etc
    lrwxr-xr-x  1 root       7 Feb 24  1993 lib -> usr/lib
    drwxr-xr-x  2 root    8192 Feb 24  1992 lost+found
    drwxr-xr-x  2 root     512 Aug  7  1992 mnt
    drwxr-xr-x  2 root     512 Feb 24  1993 opr
    drwxr-xr-x  3 root     512 Aug  3 12:44 public
    lrwxr-xr-x  1 root       7 Feb 24  1993 sys -> usr/sys
    drwxrwxrwt  5 root    1024 Sep 12 18:46 tmp
    -rw-r--r--  1 root   11568 Jul 24  1992 ultrixboot
    drwxr-xr-x 27 root    1024 Jun 10 11:28 usr
    drwxr-xr-x  9 root     512 Aug 19 15:43 usr2
    -rwxr-xr-x  1 root 3448280 Feb 24  1993 vmunix
    
    This is what I would like your output to look like:
    September 1993 has 30 days
    The root directory on gort has 12 directories
    
       2048 r-x  2 14:26 bin
        512 r-x  2 15:59 bsd-src
       3072 r-x  3 14:45 dev
       6656 r-x  6 22:25 etc
       8192 r-x  2  1992 lost+found
        512 r-x  2  1992 mnt
        512 r-x  2  1993 opr
        512 r-x  3 12:44 public
       1024 rwt  5 18:46 tmp
       1024 r-x 27 11:28 usr
        512 r-x  9 15:43 usr2
    
Make a printout of your output and shell script, mark it with:
your name
TABER CSC137
Lab 4.8: Shell script --- dir
Place the lab in the instructor hand-in box in BUS R6E, the "terminal room".
Instructor: ltaber@pima.edu** Red's Home page** The Pima College Site

Prev Up Next