What is Unix anyway?

Unix is a command line operating system.

Table of Contents


UNIX, Solaris, Linux...

In about 1969 at Lucent Technologies (Bell Laboratories at the time), Ken Thompson wrote UNIX on a spare PDP-7 computer, to play games on. Later Dennis Ritchie helped him rewrite it in C, and history was made. Originally the source code was distributed to educational institutions for free and it became very popular.

The basics of the UNIX design are this. UNIX is multi-tasking and multi-user, which just means that not only can you run more than one program at a time, but more than one person at a time can run more than one program. These programs do not running at the same instant in time but are switched among so quickly that they appear to. The kernel which is the heart of the operating system and handles memory management, device I/O, and process switching. The philosophy behind the design is that a program should do one and only one thing. Similiar to the philosophy behind C where a function does one and only one thing (interesting?). Keep this in mind and you learn about all the little programs in the system.

UNIX was the original name and now refers to a catagory of operating systems, Solaris, HP-UX, Linux and so on. Each of these is a version or flavor of UNIX usually for a particular machine. CSC is a Sun Sparc server and runs Solaris. Linux is a free UNIX project that can run on many architectures. It is also the form on UNIX we run on the PCs in the lab. There are slight differences between these flavors, but they are all basically the same.

Man pages and info

Man pages are online documents that are "straight" from the manuals for the system. Imagine knowing all the system commands and all the C functions. Well, they are all right there in the machine! Did you ever need to know the parameter list for particular function? Just type in 'man functionname', as in 'man strcmp'. You get all the information you need on the function. Ever forget the command line switches (options) for 'ls', just type in 'man ls' and there they are. It works for almost every command and function, with exceptions being shell specific commands, but we will get to that.

Man pages are broken up into various sections for functions, system commands, etc. When you see that 'sleep(1)' at the top of a man page, it means you are looking at section one of the manual, at the sleep command. There is also another 'sleep' command, 'sleep(3C)'. Section 3C contains subroutines and libraries. So how do you change sections? Try typing 'man man'. That will bring up the manual page on man and you can see the command line option for section. If you type 'man -s 3 intro' you will get an introduction page to section 3 and a listing of all the commands there. All the sections should have a introduction that will give a list of their commands.

Man pages can be a bit tricky to read at first, but once you get the hang of it, they are an invaluable tool.

The shell, processes, and I/O redirection and piping

The shell is probably what gives students the most trouble. The shell is not as warm and fuzzy as a point and click GUI, but once you learn how to use it, you will see just how powerful it is. There are four important things you should know about, and they are: the shell itself, process control, I/O redirection and piping.

The shell is the most common UNIX interface for the user. Basically you type in commands and get information back. Most computer science students at UIS use 'tcsh', because it is great for programming with. 'tcsh' can hold your previous commands and if you up-arrow back through them to get to a previous command without retyping it. Also if you use the bang (exclamation point), the shell will search back through commands for a pattern. For example if you type '!gcc', the shell well present you with the last time you typed in 'gcc'. Less typing is better! Another cool thing the shell does is support wildcards. Wildcards are just a way using '*' and '?' to represent any number of characters and a single character, respectively. By typing 'ls *.c', the shell replaces the asterisk with any filename matching the pattern, and fills the command line with those filenames sending them to the program 'ls'. It is important to remember that the shell does this matching and expansion as we will see later.
The shell can also handle multiple processes, but I won't go into this too deep. You can run a program in the background by typing 'programname &', and you will get back the shell prompt immediately. That is because your program is running but control has switched back to your shell. You can get a listing of all the processes/programs your running by typing 'ps -u username'. What to stop a background process? Do a listing to see the process idetification number (PID). Type 'kill -9 PID'. There is much more on shell process handling but you can read the man page for tcsh to find out how.
All programs have 3 "files" open when they start, standard input (stdin/0), standard ouput (stdout/1), and standard error (stderr/2). This is how the shell and your program view them. Stdin is what you type into your shell or program. Stdout and stderr are what your shell or program display to you. The only difference is that stdout buffers data, or only prints data when there is a certain amount ready. Stderr prints immediately. That is why you will generally see a core dump message before you see the text printed just before it. We must know this to understand redirection and piping.
I/O redirection is pretty cool stuff. Have your ever gotten so many messages on the screen from your program that you could not even read them because they scroll by too fast? Input/Output redirection is for you. Next time you run that program, type 'programname > foo' instead. The shell should return with nothing printed. That is because all of you output(stdout) was redirected to a file called 'foo'. If you 'joe foo' you will see all of the output of the program. Ever have a program with lots of stuff to type in? Try this 'a.out < foo', where foo is all of that stuff you had to type in. Your program will now read any input it needs from the file 'foo', instead of you typing it in. This is good for debuggin a program with lots of input up front. Well, that's stdout and stdin, but what about stderr? Try this 'gcc foo.c >& errs'. This will create a file called 'errs' and send all of the error messages there. This is great when your compiling a program and get lots of error messages! You can also append to files and other stuff, but check out the man page on tcsh for that.
Piping is also pretty cool. With piping, you can "pipe" output from one program as input into another. Remember that program with lots of output on the screen, type 'programname | more'. This pipes the output of 'programname' into the program 'more'. 'more' is just a utility to hold the screen from scrolling. You can even use multiple pipes on the command line. For example, 'foo | bar | more'. We'll see uses for piping later. In case you have not been able to find the pipe symbol, it's the broken vertical line on the keyboard. Probably above the forward slash '\'.

Editors

UNIX has many editors, probably the most infamous is vi. This was originally designed to be a line-at-a-time editor. Most students find vi hard to use, but once learned the benefit is that you will find it on every UNIX system. In case you cannot figure out how to get out of vi once inside, type the '' key atleast twice and then ':q'. joe is probably the most used editor at UIS and it is pretty straight forward using '-k' to send control sequences to the editor. Another popular UNIX editor is emacs.

Permissions

Students really seem to have a hard time with permissions, but once you know this simple technique, you should have no more problems. If you type 'ls -l' you should see atleast one line that has this 'rwxr-xr-x' out front or something like it. The first set of 3 stands for user permissions, the second for group, and the third is other. Read, write, and execute are what 'rwx' stand for. Ok, this is really simple if you understand binary and you should being in computer science. Think of each 'rwx' as a set of three binary numbers. If the permission is set(on) then you see the letter. By typing 'chmod 753 foo' the 7 stands for '111' in binary, five is '101', and three is '011'. This sets the file 'foo' to have these permissions 'rwxr-x-wx'. Some quick notes, normally your file permissions have a default of 600, which is determined by your user mask('umask'). Web documents need to be read and executable by your group and other, 'chmod 755 foo.html' --> 'rwxr-xr-x'. NEVER provide write access for your group or other to your files, as anyone could delete or change your file. Now see that wasn't hard. For more information or maybe a better explanation try looking at the man page on 'chmod'.


Home | Information | Academics | People | Resources | Contact

The Department of Computer Science at the University of Illinois at Springfield
Copyright© 2002 University of Illinois at Springfield