[WPI] [cs2223] [cs2223 text] [News] [Notes] 

cs2223, D97/98 UNIX Concepts and Commands

UNIX is a very powerful operating system. Its industrial strength make it popular among professional computer scientists. However, its inscrutibility challenges new users. UNIX is user-friendly, but not necessary learner-friendly. Here we can only cover the simplest UNIX concepts and commands. If you want to learn more, the Notes page contains a reference to introductory UNIX books and web sites.

UNIX Concepts

Shell. This is the application that starts when you begin a UNIX session. The commands you type are the inputs to the shell and what you see on the monior are its outputs. Most of the time the shell is totaly transparent, but it is useful to know that alternative shells are available. As you advance, you may want to find out about some of the alternatives.

Working Directory, Home Directory. The computer's file system consists of directories (called "folders" in windowing systems) which contain files and other directories. At any given time, UNIX considers one directory to be your working directory. When you start a UNIX session, your working directory starts out as your home directory, which is abbreviated with a "~" (tilde) followed by your login name. My home directory is ~wittels. Your working directory can be changed to any directory which you are allowed to access. Your home directory can only be changed by a system administrator.

 Drawing showing nested directories.

Path. This is the logical location or address of a file inside the computer's file system. It starts with a single directory called "/" and known as the root of the file system. The path to a file is a list of all of the enclosing directories separated by "/" and without spaces. For example, if my home directory is /usr7/wittels and there is a directory, called cs2223, inside my home directory and a file called main.C inside the cs2223 directory, then the path to the file is /usr7/wittels/cs2223/main.C. This is the file's absolute address. A file can also has a relative address which tells how to get to it from the your working directory. Using the above example, if my working directory is /usr7/wittels then the file's relative address is cs2223/main.C. If the working directory is /usr7/wittels/cs2223 then the relative address is main.C. Two abbreviations useful in specifying a relative path are "." (single dot) meaning "my working directory" and ".." (double dots) meaning "the directory that my working directory is in". Thus, from my home directory ~wittels, I can specify the pah to wilson's home directory by the symbolic address ~wilson, the absolute address /usr7/wilson, or the relative address ../wilson.

UNIX Commands

pwd - print working directory. This command printts out the absolute path to your working directory. This is the result when I'm in my home directory:

wpi.WPI.EDU> pwd
/usr7/wittels

ls - list working directory. Print the contents of your working directory. This is the result when I'm in my home directory:

wpi.WPI.EDU> ls
cs2223       public_html

You can also add the option -l to get a "long" listing:

wpi.WPI.EDU> ls -l
total 16
drwxr-xr-x   2 wittels  1174        8192 Oct 16 16:51 cs2223
drwx-----x   3 wittels  1174        8192 Oct 13 16:10 public_html

cd - change working directory. This example shows how the command is used.

wpi.WPI.EDU> pwd
/usr7/wittels
wpi.WPI.EDU> ls
cs2223       public_html
wpi.WPI.EDU> cd cs2223
wpi.WPI.EDU> pwd
/usr7/wittels/cs2223
wpi.WPI.EDU> cd ..
wpi.WPI.EDU> pwd
/usr7/wittels

cat - concatenate. There are two uses of this command.

cat file1 displays file1 on the screen.

cat > file1 stores everything you type into file1. UNIX stops storing when you type control-d.

more and less - diplay a file one screenful at a tme. Whereas cat file2 will whip a large file2 across the screen stopping only at the end, more file2 will display it one screenful at a time. Press space to move to the next screenful; press q to stop the display. The command less file2 is similar to more file2 except that, on X-window systems, a scroll bar can be used to scroll through the entire document.

cp - copy a file. cp file1 file2 copies the contents from file1 into file2. If file2 did not already exist, it is created. If file2 did exist, its old contents are erased and replaced by the contents of file1. Note that file1 and file2 can be the absolute or relative paths to the files. Note cp can also be used to copy an entire directory and its contents.

mv - move a file. mv is same as cp except that the first file is destroyed. This can also be thought of as a way to rename a file.

rm - remove a file. Delete a file without warning and without hope of recovery. You can use rm to delete a directory (and all of its contents) by using the -r option. If I were to type rm -r ~wittels, it would significantly ruin my day.

mkdir - make directory. Create a directory in your working directory. For example, to make the cs2223 directory I went to my home directory and typed mkdir cs2223.

rmdir - remove directory. But only if the directory is already empty. rmdir cs2223 won't work unless everything inside has already been removed.

man - manual. This command shows you the manual page for a UNIX command. For example, man ls will tell you what the UNIX ls command does and what options are available. The manual pages will be displayed using the more command (space to show the next screen; q to quit). To find out more about this command type, of course, man man.

The Next Level of the Game

Some UNIX features combine great power with great danger. Here are a few.

Safety Features and Confirmation - There aren't any. UNIX assumes you know what you are doing. If you tell it to destroy your entire MQP, UNIX won't ask "are you sure you want to do that?". Nor will it tell you when the destruction is complete. UNIX is efficient; it is generally not possible to recover what you told UNIX to destroy.

Case Sensitivity - UNIX is case sensitive. That means the files wpi.c, WpI.c, wPi.c and WPI.c are all different. This can sometimes cause confusion. For example, if a file is generated in an environment which is case insensitive (eg, DOS), it may not work properly on a UNIX system. Also, gcc assumes a file with the extension .c is a C file while g++, the C++ compiler, assumes a file with the extension .C is a C++ file. Neither compiler can be fooled into accepting a file with the wrong extension.

WildCards - pathnames can contain "wildcards" which allow you to specify the path when you only know part of a file's name, when you wnnt to work on more than one file at a time, or when you are too lazy to type the whole name.

"?" means "ignore any single character". For example, rm wil?on.c will remove files wilson.c, wilton.c, and wilxon.c but not willton.c and not wilon.c.

"*" means "ignore any number of characters, including no characters". For example, rm wil*on.c will remove all five of the previous examples. The most dangerious command in UNIX is rm -r * I'm a professional. Don't try this at home.

There are other wildcard symbols available.

Control-C - This key combination stops almost anything in UNIX. That is useful because some programs, especially when you are trying to get them to work, won't stop by themselves.

Quotes - If you put "quotes" around an address, wild cards are ignored. Thus, you can create file names such as my file.c (note the space) or my*file.c. (note the *). Perhaps you can even find a way to create a path name that includes a quote.

 

--------------------
[WPI Home Page] [cs2223 home page]  [cs2223 text] [News] [Notes] 

Contents ©1994-1998, Norman Wittels
Updated 14Mar98