HW1_WRITEUP, containing the answers to the questions posed below.
classifiedsdirectory you are asked to create.
cse230in a convenient place. Go to that directory, and create the
HW1_WRITEUPfile. Then execute the following commands:
classifiedsdirectory you made for Part II to your
cse230directory. The second command will hand in the
HW1_WRITEUPfile, together with the entire contents of the
This part of the assignment, doesn't require an extensive amount of hand-in. However, you shouldn't take a minimalist attitude toward it. Try to explore beyond the specific tasks I have given below. If you are already familiar with most of what is covered, treat the assignment as an opportunity to expand your knowledge.
passwdcommand. Read about this command and use it.
.cshrcin your home directory are used by the C shell to initialize your working environment. Check whether you have these files using ``
ls -a''. (The
-aoption is required to get
lsto list files starting with ``.'', which it normally does not list.) If you are a new user, you won't have these files. Instead, you will automatically be using the system defaults, which are in the files
NOTE: If you have copied
.login files from some other system,
I highly recommend that you remove them and start afresh.
Many ``problems'' that are reported to me are in fact caused by
people blindly copying
files from another system. The system defaults on the UG lab are
set up so that they are reasonable starting points for most users.
Do not add anything to your
file that you do not understand.
When you log in, the C shell executes these files in the following
.cshrc in your home
directory (if it exists), and finally
.login in your
home directory (if it exists). If the C shell is not running as
a ``top-level'' login shell, then it only runs the
Although there is a certain component of taste involved in what
you put in
.cshrc and what you put in
in general you have to put things that are not propagated to subshells
as part of the environment in
.cshrc. All other stuff
should generally go in
Put a line that reads simply:
.login, so that when you log in you will be informed if there are any new messages to read.
.loginfile, using the
setenvcommand of the C shell.
The following is an example of commands to set some important
environment variables. These commands (or your own customized
versions) could be put in your
PATHenvironment variable controls where the shell looks to try to find binary executables for commands you type. The
EDITORvariable states which editor you prefer, and is consulted by some programs (such as mailers) that start an editor. If you don't set this, you will probably end up in
vi(the default editor) at some point. The
PAGERvariable determines which program you prefer for paginating output to be viewed on a screen. This is important for the correct operation of the
mancommand. The default pager is
more. I prefer
less. (See section 3.6).
Other important environment variables are
tells the official name of the type of terminal you are using,
DISPLAY, which is used by X Windows programs to
determine which server (screen) to use as the display device.
QUESTION: From shell command level, execute the command:
ls. Now try
/bin/ls. In your writeup, explain the results. You can recover from this situation by logging out and logging back in again. In your writeup, describe a way to recover that does not involve logging out.
Using the command
which, find out the location
(full pathname) of the
xterm command. Put it
in your writeup.
printenv command of the shell, find out
what values you have set for the
TERM and the
DISPLAY environment variables. Put them in your
umaskcommand controls the default permissions that files or directories will have when you create them. By default, your
umaskis set to
022, which means that write permissions are masked off for everyone but you. However, this means that by default everyone on the system will be able to read your files unless you take steps to prevent them. Another common
077, which by default masks off all permissions for anyone other than you. I recommend that you put the command:
Try setting your
umask to various values.
Then, create files or directories and use
ls -ld to list them. Briefly explain the results.
ducommand can be used to find out how much disk space you are currently using. Read the man page and try it out.
QUESTION: How can one cause
du to display
its information in units of kilobytes? How about in units of
512-byte disk blocks? In megabytes?
QUESTION: What is your disk quota?
Attempt to exceed your disk quota by making a number of copies
of a large file
/usr/share/dict/web2 is convenient.
in your home directory. What happened to the last file you
tried to write? Now delete all the junk files from your
lscommand. Find the simplest way you can to use
lsto determine all the files under your home directory and any subdirectories that have been modified in the last day.
cpcommand is used to copy files from one place to another on the system. Find out how to use
cpto copy the entire hierarchy of files under your current directory to
grepcommand is used to search for patterns in files. Read about
grep. Then find all the files in the directory
/usr/include(the C system header file directory) that have occurrences of the string
To take advantage of the full power of grep, you need to understand about regular expressions (2.17). For now, though, you can limit your attention to using it to search for fixed-string patterns.
findcommand is extremely useful and powerful, but has a syntax that is somewhat difficult for the neophyte. Read about it. Then, construct a
findcommand to change the mode (protection) of all the regular files under your home directory to mode
600(read/write by you, no permissions to others). Construct a find command to change the mode of all the directories under your home directory to
700(read/write/execute by you, no permissions to others). Leave your home directory with mode
755, otherwise X Windows won't work.
If the above commands were too easy, try to to construct a "find"
command to find all the regular files (not directories) under the
/var that have not been modified in one
week, and for each one to prompt you and ask if you want to view
that file using "more".
gzipcommand is used to reduce the space occupied by a file by performing data compression on it. The
gunzipcommand uncompresses a previously compressed file. Read about
gzip, then try it out on various kinds of files, including text files and binary executable files. In general, what are the compression ratios for the various kinds of files you tried? Make a copy of a text file, compress it, then uncompress it, and use the
diffcommand (3.10.2) to check whether the result is identical to the original file.
/bin/sh) shell scripts to be invoked by the World Wide Web server on
www.ug.cs.sunysb.eduin response to requests from clients on the Internet. You will use the Common Gateway Interface (CGI) standard for passing data from the client to the shell script.
Your objective in this assignment and the next will be to construct a CGI-based system that permits clients on the Internet to read and post classified advertisements. For the moment, you will concentrate on displaying advertisements already online.
public_htmlof your home directory, and to make sure that you have set ``world read and execute'' permissions on it. If your user ID is
fred, then when somebody on the Internet attempts to access the URL of the form
www.ug.cs.sunysb.edu(actually the same machine as
public.ug.cs.sunysb.edu) will respond by sending the file:
All files you wish to make available on the Web must have ``world read'' permission set. In addition, all directories the Web server must search to find these files must have ``world execute'' permission set.
To test out whether the Web server can access your
directory, you may copy
this file and put it as
Welcome.html under your
Also create a subdirectory
classifieds under your
public_html directory, and create a subdirectory
Using a Web browser, access the URL:
In case something went wrong, you can likely get some information about what happened by looking at the Web server error logs. To view these, you have to log in on www.ug.cs.sunysb.edu and look at the files
lessto view these files. You'll have to view near the end of the file to see recent messages.
POST, then if you have installed the
select.cgiscript properly, you will see a message indicating that you have successfully invoked the
select.cgiscript, and it will display for you the arguments that were passed from the form.
Basically what happens when you click on the
is the Web server invokes the
main.cgi shell script.
This script consists essentially of a bunch of
commands, which generate HTML code telling your Web browser to display
the form you see.
When you click on the
on this form, the Web server invokes the
which again consists of
echo commands to output HTML code
telling your browser to produce the display you see.
This time, though, the script uses the
to obtain information passed from the form and assign it to shell
variables. For example, within the
the shell variable
FORM_category variable has as its
value the menu item that was selected in the form.
select.cgiscript. For this assignment, you are to do two things:
main.cgiscript so that, instead of displaying a fixed list of categories in the menu, it instead obtains the names of all subdirectories of the directory
classifieds/adsand uses those names as the menu items instead. Thus, if
Computers, these are the menu items that will be displayed in the form.
select.cgiscript so that, instead of displaying the CGI arguments to the form, it interprets the value of the
FORM_categoryvariable as the name of a subdirectory of
classifieds/ads, it obtains a list of all the files in that subdirectory, and then constructs and displays a list of hyperlinks to those files.
For example, if the
has the value
Automobiles, and the
then your script should output HTML code like this: