Lab 02: Computer Ethics, Policies, and More UNIX

This week's lab session will review the contents we learned last week, get familiar with the UNIX programming environment, and then introduce you more about computer ethics, policies, and more UNIX knowledge.


Do you have any questions from last week?

During this time, practice what you learned last week about basic UNIX commands, Editing source code by using pico or vi. Compile your C/C++ source code by using gcc/g++ respectively.


Computer Ethics, Policies, and More UNIX For this lab, you may also need to access a set of on-line UNIX help pages. This is a page of useful UNIX help information. We have put a link to this page on the main page for COT3002L. It's also under the link "Computing Resources" on the CSE Home page. Answer the questions maked in bold that are given on this Web page.
Files, Links and File Protection We want to make sure you understand some details about files and directories under UNIX. As you do this section, you may find it very helpful to use the man pages for ls or the section of the on-line UNIX Web pages devoted to files etc.

The ls command "lists" the names of files or shows you information about files and directories. This command always takes either one or more files or directories as the last argument. (If you don't give it a file or directory, it looks in the current directory.) Also, there are many options. Let's find out about them.

The -s option tells you the size of a file. List the files in the home directory of the user cot3002l by typing: ls -s ~cot3002l
(Note that's an "ell" not a "one" at the end of that user-id.)

Question 1: What is the largest file and how big is it?

Question 2: Use the man page or other help information to say what the unit of measurement is reported by ls -s. (I.e., is it bits, bytes, megabytes?)

Hint: if man ls prints out too much to see in one screen (!!!), you should pipe the output into more like this:
man ls | more
You should always do this when a program or command produces a lot of output. Or, this might be a good time to remember the xman version of man that uses the Windows interface.

Another very useful option for ls is the "long" option; this shows a lot of detailed information about the files. Type ls -l ~cot3002l

Question 3: What is the date listed for the subdirectory Mail that's there? Also, what does the date show mean: is it creation date, modification date, or what? (Hint: use man etc. to find out more about the -l option.)

A useful option to combine with the -l option is -t for "time" which lists the files by date, with the most recent file at the top.

Question 4: What is the oldest and the most recent file or directory in ~cot3002l/public_html? This is the directory where all the Web documents for this lab class are found. Hint: if there is too much to see in one screen, you should pipe the output into more, of course.


File Permissions The first column printed by the ls -l command has a lot of useful information that is hard to read. (The man page describes this. Let's explain it by looking at an example:
drwxr-xr-x  3 cot3002l      512 Aug 20 12:40 Homework
drwx------  2 cot3002l      512 Jun 18 14:17 Finances
-rw-------  1 cot3002l    74596 Apr  8  1996 prog3.tar.gz
-rwxr-xr-x  1 cot3002l    24576 Oct 29 10:14 a.out
The first letter says something about what type a file is; if it's a d then it's a directory (which in UNIX is just a special kind of file).

After the first letter, there are three sets of 3 characters (9 total, eh?) that tell you about the permissions set for that file or directory. These letters are either r for "read", or w for "write", or x for execute. The first set of 3 characters are the permissions that you (the user) have on that file. The second set of 3 characters are the permissions for users in your UNIX "group", and the final set is for all others. (Students are usually in one group. Type id to see what group you're in, if you're curious.)

The above output tells us that Homework is a directory that anyone can look into (with ls) and see what files are in there. But the directory Finances is not accessible by anyone except the owner. The file prog3.tar.gz is also only readable and writable by the owner. Finally, the file a.out is executable by anyone; also, the owner can delete it (because he or she has "write" access to it).

Question 5: In the home directory of user cot3002l what are the directories that are readable by anyone? What directories are only readable by the user cot3002l himself?

Comment: There are other useful options to ls, but you can find them on your own. It can pretty much tell you everything you want to know about a file. One of my favorite options is -F which shows me the file type (directory, executable, etc.) in a short-hand manner (that is, more than one file on each line). Try it.


How to Protect Your Files You can change permissions on your own files with the chmod command ("change permissions mode"). Again, you should consult the man page or the on-line UNIX Web pages for more information on this very important command. When using chmod you tell it how you want the permissions to be set and then give it a list of files or directories.

To specify how the permissions should be set, there are two forms. One uses 3 digits that correspond to the three user-classes described above (user, group, all others). Each digit represents a 3-bit pattern where each bit shows if read, write or execute is allowed. See the help information for more details; it's really not that hard.

But it's not as easy as the second method. To specificy a permissions, use one or more of the letters ugo (user, group, others), then followed by a plus or a minus, then followed by one or more of the letters rwx (read, write, execute). Some examples:

chmod og-rx prog1.c Mail
chmod +rx ~/public_html
chmod og+rwx delete-me Open-directory
chmod u-w Important-file
chmod +x My-script
The first command will not allow any one but you to read the C file or look into the subdirectory Mail. The second command lets everyone see and execute the files in your subdirectory public_html (which is where you can put your own Web documents). The third command is very dangerous: it let's anyone change or remove the file delete-me and let's anyone remove the directory Open-directory or put files in it. The fourth command takes away your own permission to delete the file, so you can't delete it yourself. (If you really want to remove it, you need to give yourself write permission back, then use rm.) The final command makes the file My-script executable. (You'll need to do this when you write your own shell-scripts.)

Question 6: What is the protection of your own home directory? Can others read the files in it? If you have a subdirectory for your assignments for this lab, change the permission of it so others cannot see your files in it.


Searching Files and Regular Expressions Most computers have a command for searching a file (or files) for lines that include some string or match some pattern. Also, commands like ls -l are more useful if you can use some kind of pattern to indicate which files you want information about. So there are many times we need a kind of "language" for specifying patterns. A very common way to specify a pattern for a search or a match operation is called a regular expression. These are used often in computer science and on UNIX systems, so we will introduce them to you now. We'll use the "find lines in a file" command, grep, to show you how regular expressions work. (Once you learn them, you can use them in editors like vi or emacs, with the ls command, and in many other places.)

The on-line UNIX Web pages have a very nice description of regular expressions with grep. (From the top, it's under the section on "File Manipulation Utilities".) We'll give you some simple examples here, but you should have a look at this on-line help to learn more when you have a chance.

Regular expressions look a lot like simple strings, but they can have some special characters in them with special meaning. For example,
grep 'hello' /usr/dict/words
searches for lines in the file /usr/dict/words that contain the sub-string "hello". Try it. (Hint: we normally put regular expression inside single-quotes when using grep since the shell will try to match the regular expression as if it were a file-name pattern.) The file used here is the system dictionary used by the spell program. Of course you could use grep on any file, especially your own files.

Maybe you want to find lines in this file that begin or end with a pattern. In regular expressions, the caret symbol ^ is an "anchor" that means the beginning of the line, and the dollar symbol $ means the end of the line. For example, grep '^hello' would find all the lines that begin with "hello" in a file, and grep 'ally$' would find lines ending in "ally" in a file.

Question 7: How many words in the system dictionary file /usr/dict/words begin with "inter"? How many end in "ment"? (Hint: Don't want to count all that output? Do you remember pipes? Remember the wc command that counts words and lines? Ask your TA if you've forgotten.)

In regular expressions the "star" * means "match any number of the preceding character". A single period . means "match any single character" no matter what it is. For example, grep '^lo*$ /usr/dict/words returns "l" and "lo". Why is the first one a match? Because "start" will match zero or more occurences of 'o'. To find the lines that begin with "lo" and end in 'r' you'd type use '^lo.*r$' as your argument to grep.

Question 8: In the dictionary file, find what words begin with 'z' and end in 't'. Also, find what words begin with 'l' and end in 't' and have only one letter in between.

You can also specify that a group of characters be treated as a "set" when doing matching by enclosing them in "square brackets". For example, grep '^[aeiou]t' will find lines that begin in a lower-case vowel followed by a 't'. Lines beginning with "at" or "ot" would match, but lines beginning with "in" or "yt" would not. Note that grep on UNIX is sensitive to the case of letters, so if we wanted to include upper-case vowels too we'd use '[aeiouAEIOU]'.

Question 9: Use the above method, and write down what words in the system dictionary begin with "norm" or "Norm".

Question 10: Use the man page for grep to find what option to the command makes it ignore difference in the case of letters. Also, find out (and write down) the option that reports the line number of each line that matches a pattern. (See how this would be useful for looking for things in your C files?) One final note about the square bracket notation. You can use the caret symbol ^ right after the opening bracket to mean "match anything but these characters". So grep 'q[^u]' /usr/dict/words will find any line that contains a 'q' but is but is not followed by a 'u'.

You can use these same patterns in the UNIX shell whenever you need to type a file name. In this case, you do not put the single quotes around the pattern.

Question 11: In the source file directory for this lab class, ~cot3002l/src, what argument would you use with ls to show the C program files that do not begin with a capital-C? What command shows you the files that are not C files (i.e. do not end in .c)?


Ethics, Appropriate and Illegal Use of Computers There are rules and guidelines pertaining to the use of computers belonging to the CSE Department and any machine or network resource (like email) at FAU. The CSE Department follows FAU guidelines and state laws in such matters. You'll find a complete description by following the link on the main COT3002L page, "Policies on Computer Use." This section uses some of that information for the questions, but you are responsible for reading and following all of the rules listed on that page. (Use of these computers is a privilege that requires you to follow these rules.)

Please read the university's statement on a Code of Computing Practice that is part of the university's policies. Click on the link to go to it. Read it and answer the following questions.

Question 12: What is the title of the section that states that students are not allowed to copy computer files related to coursework? Also, what kinds of language are considered inappropriate for computer communications within the university because they violate accepted ethical standards?

Please read the university's Network Computing Policy. You may have been given a copy of this in class or when you got your computer account, too. This policy (and the ethics policy above) are to be followed when using computers at FAU. Many of the items are obvious: don't crash systems, don't read other people's email, don't pirate software, don't introduce viruses, etc.

Question 13: Are you allowed to give someone else your user-id and its password? Can you think of a reason why this might be prohibited? (If so, briefly describe.)

Question 14: Can you use your computer account at FAU to advertise your family's business, or to create Web pages for your own consulting company? Which subsection addresses this issue?

Note: violations of these policies may lead to suspension or dismissal, as noted in the introduction of this document. So please act with maturity and professionalism.

As you may have noticed reading the previous document, the university and its staff will cooperate (and in fact, must cooperate) with law enforcement officers if local, state, federal, or international laws are broken using FAU machines or students accounts. This can have very serious consequences. In fact, incidents involving FAU computers have led to individuals being arrested to face state charges, or being severely disciplined (perhaps even fired) by their employer. You may believe you won't be caught, but it could happen. Is it worth the risk? No. You don't want to have to list this on every job application from now until you retire. You don't want to lose your right to vote. Be smart!

Florida has a very strict "Computing Crimes" statute which is on the Web along with all Florida laws. (Pretty neat, huh?) Visit this site and skim through the information (or use "search" in Netscape) to answer the following question:

Question 15: What charge can be brought against someone who accesses a computer or network without authorization (also known as "hacking")? The kind of answer we're looking for here is something like "third degree misdemeanor" or "first degree felony".

In the United States of America, we are guaranteed the freedom of speech and expression. Therefore you might think that a student should be free to use FAU computers accounts for email or Web pages that contain any kind of expression, even obscene or racist language or pictures.

Question 16: Do the CSE rules and the FAU Code of Computing Practices allow a user to use obscene or racist pictures or langauge on Web pages? Why does the university have right to prevent a user from doing this? (Hint: for the same reason that a company might not allow an employee to do this.)


Conclusion. That's all for this lab. Again, you should become familar with all of the commands and concepts presented here. The Web pages found at the link at the top of this are a great resource. Also, there are some good books on UNIX that explain many of these things. (You might check our library for one.) If you have questions, ask your lab TA or Dr. Horton or any other professor who knows UNIX well. (Not all do, of course, since some are PC or mainframe experts.)

And please take some time to read and understand the various policies on appropriate use of computer resources here at FAU. We don't go looking for violators, but if we find someone doing something inappropriate we certainly take action.


Last modified 12/28/2006.