A VERY BRIEF INTRODUCTION TO UNIX                                                               Feb 1998

Unix (which is not an acronym for anything) is the operating system running on several Loyola computers, including the math/cs department’s abel (a dual-processor Sun workstation), abel’s Sun relatives backus, hopper, knuth, mccarthy, milner, scott, strachey, and IT’s orion. Typically unix systems support multiple users logged in at once, although it is also common for the public unix workstations in DH341 to be used by only one person at a time (only one person can use the console, but others can be logged in remotely).

In this memo it will be assumed that you are either logging in remotely to abel, or directly at the console to one of abel’s relatives.

Abel was named for the Norwegian mathematician Niels Henrik Abel, 1802-1829

This brief memo is intended to get you started. After that you should consult the online man pages; there are various online reference manuals for special applications too. Most of this handout pertains to using unix itself and running programs and doing basic editing.

Remote login

Essentially all the PCs at Loyola can be used to log into abel remotely, via telnet (there are other network login methods equivalent to telnet but technically distinct, eg rlogin and ssh). A telnet connection is a text-based connection; you can’t run graphical-based programs. Telnet client programs (the program on the PC end) vary in functionality; some allow you to resize the window and to scroll back over previous lines and some don’t.

To log in, you typically start up a telnet client program and find where to enter the name of the remote system; try looking for a menu item called connect. Find a box where you enter the name of the remote system; enter abel.math.luc.edu if it’s not already there. Press ok, and you should get a login: prompt from abel. If you don’t, ask for help. If you do, type your math/cs-department userid (generally the same as your university/groupwise userid), press return, and at the password: prompt type your password (generally not the same as your groupwise password; check with your instructor or an advisor). This should get you to the abel> prompt.

To log off, type exit, or else press cntl-D.

Console login

The other way to log in to a unix system (at this time only applicable to the public unix abel-relatives in Damen 341) is to sit down at the console. There is a box for your username and password. Once you log in, you should be running the X-windows windowing system. This lets you open multiple windows, and run graphical-interface programs.

Overall, console login should be relatively straightforward. The mouse works a little differently from MSwindows, though; typically you can bring up a menu anywhere by clicking with the rightmost mouse button. This works if you click in the menu bar, but also in the middle of a text pane, and even in the screen background. Right-clicking in the background, in fact, brings up the general menu (roughly equivalent to MS’s start menu); one of the items on this menu is the exit selection used to log off.

Once you log in, you will need a command window to work with. The usual command window is a program called xterm. You can start multiple xterms, using the background menu to create them. Your xterm window should show a prompt like hopper>, if you are on the machine named hopper. You may have to click on your xterm window to activate it, or else move the mouse into the window.

Even though the machine you’re on isn’t abel, and even though the prompt won’t be abel>, all the DH341 machines share with abel both the software libraries and, more importantly, your home directory (where your own files will go). Thus, if you are at one of the abel relatives there is generally no reason to telnet to abel; you can just work on the machine you’re at.

Commands

To enter commands in unix, type them in after the prompt and hit the RETURN key. Unix is case-sensitive, and almost all commands are to be typed in lowercase. Any command options or file names are separated from the command name and from each other by spaces. Normally you can correct any typing errors with the backspace key, provided you make these corrections before pressing RETURN. However, it is possible for your terminal to be set up incorrectly, so some other key erases instead. Try the following test: type a few characters, and then backspace until they are all erased, and then press RETURN. Contact your instructor or an adviser if backspace doesn't seem to erase anything or if you get any kind of message back from the system afterwards.

Here two simple commands you can try right away. Each is explained in the comment to the right; don't type these comments.

date (* prints the current date *)

who (* prints a list of who is on the system. Can you find yourself? *)

Special keys

To stop whatever you are doing if you get stuck, type CNTL-C (hold the Control key down and type C). This also halts your programs if they get stuck in an infinite loop. A CNTL-\ will also work. If all else fails, you can log in from somewhere else and use the ps command to get your process numbers and then the kill command to kill them.

Files

Unix filenames can be of arbitrary length, and there is seldom a specific understanding regarding an "extension". The '.' character is just an ordinary character in file names, which can thus contain no, one, or several '.'s; in DOS, the '.' has special significance and must always appear at a certain position. Unix uses / as a directory/file separator character; eg /home/pld/manuals/unixmemo; windows, of course, uses \. Unix filenames are case-sensitive and can contain "invisible" characters; a common convention for C and C++ files is that C files end in .c and C++ files end in .C or .cpp.

Most of the time you will refer to files by simple name only, and UNIX will look for them in your own directory [more precisely, your current working directory]. Thus, you will type the names of your files as, e.g., 1.C, homework1.c], lettertomom, and so forth. However, you always have the option of giving the FULL name of your files; e.g. /home/pld/372/1.C. This latter form, beginning with a slash, will most likely be necessary if you need to refer to files created by your instructor.

Here is a brief summary of file-manipulation commands. The first three concern directories, then cat and more let you look at files, and then mv, cp, and rm let you rearrange files:

pwd prints your working directory. Try it.

cd changes your working directory. 'cd' alone changes you to back home; cd /usr/bin would change you to the /usr/bin directory. This directory happens to contain many command files.

ls lists the files in your working directory. Probably boring if you haven't created any files yet to list. Try "cd /usr/bin" followed by "ls", or just ls /usr/bin; this should list many of the commands (binary files) that are available. Also try ls /etc and ls /bin.

An option that is useful with ls is -l; typed "ls -l". This gives you a long listing, including the display of permissions. Permissions like "rw" or "rwx" mean that only you (the owner) has access to the file [the significant thing is all the dashes at right, meaning 'no access' to others]; all the files you create should look like that. A permission beginnning "d...." indicates a directory.

cat filename   Types out the named file on your screen. Try "cat .profile". Listing a directory with cat is possible, but not comprehensible.

more filename   Types out the file one screen at a time; use for looking at large files. Type a <SPACE>  to view the next screen; other characters let you scroll back up.

mv filename newfilename   Moves a file from one place to another; i.e. renames it. Example: mv hwk1 hwk1.p

cp filename newfilename   Copies a file from one place to another.

rm filename   Deletes a file. Beware of * and ? in file names; they are special matching characters.

head filename   Look at the first few lines (or last few, for tail) of a file; handy for checking contents.
tail filename

The special matching characters * and ? can be used in any command. A * matches everything, so "ls *.c" would list all your files ending in ".c", and ? matches a single character so "ls foo.?" might list foo.c, foo.C, foo.h, but not foo.text. Be careful with * and the rm command! You cannot recover a file once it is gone, although if the file was 24 hours old or more your instructor might be able to arrange to have it reloaded from the nightly backup tape.

lpr filename   Will cause the named file to be printed on the printer. Be sure you know which printer!

man command Displays the online manual page. Try man man or man pwd.

passwd Prompts you for your old password, and then a new one (which you must type twice).
Your password is then changed to the new one.

chkey   If you’ve never changed your password on abel, you may need to run this once. It will ask you for both your login password and also your NIS+ password; the latter is simply nisplus.

grep string files   Searches the files for lines containing the given string (or, more generally, a pattern).

ps Lists processes. There are many options; see man ps.

Problems

Your files are not found. You may not be in your own directory. Use pwd to find out; use cd to fix.

Using the editor garbles the screen.   Possibly the terminal type is set wrong. Try the following:
      TERM=vt100      (if logged in via telnet; use TERM=xterm at an xterm window on the console)
      export TERM
Use echo $TERM to check the current value of TERM.

Programs are not found: See Your PATH, below.

Your PATH

Unix (like DOS) searches for executable files based on the contents of your PATH shell variable. On orion, you may wish to include the math department's directory /usr/local/math/bin: include the following line in your .profile file to do this: PATH=/usr/local/math/bin:$PATH; export PATH

C & C++

Files containing C programs must end in ".c"; C++ program files must end in ".C" or ".cc". To compile a C program in the file sample.c you issue the command gcc sample.c. If there are no errors these will all create an executable program in the file a.out. To run the latter, just type a.out. To use C++ you use the g++ compiler.

LISP

Lisp in the math/cs department is available only on mccarthy; you need first to telnet to that machine. Once there, to start lisp the command is simply lisp.

Input/Output Redirection

Any command or program that normally reads its input from the terminal can be forced to read from a given file instead; similarly, any command that normally prints its output on the terminal can be forced to send its output to a file. One uses the 'redirection characters' '<' and '>' to do this. If program a.out normally reads from the terminal and you have some data for it in file foo, you can have a.out read this data with

a.out < foo

The '<' is intended to suggest 'from', or 'out of'. Similarly, '>' suggests 'to' or 'into'; to save the output of a.out into a file bar you would type

a.out <foo >bar

Warning: Using '>' when you meant '<' will destroy the input file you had prepared, as output will go into the named file and will erase what had been there. Be careful. Make backups!

Input redirection is often useful when you want to debug a program entering test data from the terminal, and then want to make the final run with data from your instructor's file; e.g. a.out < /home/mth/pdordal/372/data1.

Pipes

Commands can be chained together by | into a pipe. For example, in the pipe
         who | grep pld
the output of the who command becomes the input to grep, which prints those who output lines that contain the substring "pld". This is similar to who > tempfile; grep pld < tempfile, but without the need to create an explicit tempfile.

Turning in Programs

Consult your instructor for specific details here. The command script captures a copy of everything on the terminal screen into a file named typescript, up to the next time you type CNTL-D; you can then print this file later. Be careful; if script is not running then CNTL-D logs you off. Do not attempt to run an editor if script is running.

Editing

For editing from a telnet connection, the most popular editor is pico. It’s a little slow for major changes, but it’s easy to use.

If you’re at a console, the easiest editor is textedit. It starts up a separate window, in which the usual mouse operations all work. You will usually want to be able to continue using the shell window from which you started textedit; to do this you run textedit in the background by ending the command with an &: textedit filename &.

It is usually a good idea to have one window for editing and another for program running. If you’re at the console this is straightforward; if you’re logged in via telnet then you should simply get into the habit of starting a second telnet session for your editing window.