Unix is a multiuser, multitasking, networking operating system available on many University computers. The system has a long and diverse development history and is currently available from many vendors in a variety of different forms (or 'flavours'). One of the most popular commercial unix variants is distributed under the name 'Solaris' by Sun Microsystems. Solaris is running on many Goldsmiths servers, such as Aries and Scorpio. In recent years, Linux has become a very popular, freely available unix variant and several organisations are now producing their own brands (or 'distributions') of Linux. Among these, RedHat Linux has become one of the most established and widely distributed versions and this is the system running on Igor, the MCS Departmental server.
Unix systems come complete with an online help system which is available for all users. This online help is stored in a database of 'man' (manual) pages which are accessed using the 'man' command.
The 'man' command can be used to get help for a specific command, or to search the help database for pages containing a given keyword. For example:
man man
will display the manual pages for the 'man' command itself, and
man -k help
will find all manual pages that contain the keyword 'help'.
To change your Unix password, type 'passwd' at the command prompt.
You will first be asked to authorize the operation by entering your
current password. You are then asked to enter your new password and
then to enter it again to confirm that you typed it correctly. This
confirmation is required because none of the passwords you type will
be displayed on the screen (for reasons of security), so you will
not be able to see them.
For more information about the 'passwd' command, type 'man passwd'.
A Unix filesystem has a hierarchical structure that can be visualized
as an upside-down tree composed of 'directories'. At the top of the
directory hierarchy is the 'root' directory, which is referred to as
'/' (forward-slash). This directory contains many subdirectories which
have names like 'usr', 'bin' and 'home'. Subdirectories can themselves
contain other subdirectories and each directory can contain any number
of files.
Your 'home' directory, the directory that contains your own personal
files, resides at a specific node within this directory structure.
Its location is defined by specifiying the list of all the subdirectories
that are traversed to reach it, starting from the root directory. For
example, if your username was 'foobar', your home directory might be
specified by the following:
The leading slash represents the root directory. Then 'home' indicates
that you are within the 'home' subdirectory of the root, the directory
that contains all user accounts. Within the 'home' directory is a
subdirectory called 'foobar' that contains the files owned by user foobar.
You can extend the directory structure further by creating your
own subdirectories within your home directory which you can use to
contain different kinds of files (programs, text, coursework, etc.).
For example, user foobar might create a subdirectory to hold files for
their CS208 module and separate subdirectories within that to contain
the files for each coursework. The full specification for the directory
containing the files for the first coursework might then be:
You display a list of files by using the 'ls' (list) command.
The default operation of the 'ls' command (ie. the action it performs if
you just type 'ls' and press 'Enter') is to display the names of all
files in your current directory in alphabetical order. You can tell
'ls' to display more information about your files by adding one or
more extra arguments after 'ls'. You can also list the files in other
directories by specifying the directory before pressing the 'Enter' key.
For example, to display all files in a subdirectory called 'bin', type:
To display a long file-list containing more information about each
file (owner, size, creation date, etc.) in the current directory, type:
Finally, to display a long list of the files in the 'bin' subdirectory,
type:
For more information about the 'ls' command, type 'man ls'.
You move to another directory using the 'cd' (change directory)
command. To change to a subdirectory with your current directory called
'bin', you would type:
To change back to your previous directory (ie. the 'parent' directory
of 'bin'), you can type:
Since all directories (except the root) have a single parent directory,
the two dots are used as shorthand to refer to the parent of the current
directory.
You can change back to your home directory by entering 'cd' on its own
with no parameters.
For more information about the 'cd' command, type 'man cd'.
You can create and remove as many sub-directories as you like in your
home directory by using the 'mkdir' and 'rmdir' commands. For example,
to create a new directory called 'CS208' in your current directory type:
You can also create sub-directories within your sub-directories to
further sub-divide your files. To create a sub-directory within the
'CS208' directory called 'cw1', you could type:
or, alternatively:
Sub-directories can only be removed if they are empty, that is, if
they contain no files or sub-directories. You could remove the 'CS208'
and 'cw1' sub-directories created above by typing:
Files can be deleted using the 'rm' (remove) command.
To delete a file called 'oldfile' in the current directory, type:
You can also delete multiple files in one go, an operation you
should only perform with great care. The following commands delete
all files in the current directory and the 'tmp' subdirectory,
respectively:
The shell expands the asterisks (*) into the filenames of all
files in the specified (or implied) directory.
To communicate directly with Unix, you use a unix shell.
A shell prompts you with an input-line and interprets the commands you type.
Several different shells are usually included with Unix, with names like sh,
csh, ksh and bash. Any of them can be used to perform the same basic tasks
and most also include a number of unique features. One of the shells will be
designated as your default login shell. You can, however, change to any shell
you prefer by typing its command-name after logging-in.
Sequences of commands that you need to enter frequently
can be saved in a file called a shell 'script'. You can then instruct the
shell to execute the all of the commands in the script by simply typing its
filename.
A script is an ordinary text-file that has 'execute' permissions set.
Simple scripts can be created using 'cat':
Note: The tilde (~) is an alias for your home directory and the
end of the file is indicated by typing Ctrl-D (^D).
More complex scripts can be created using 'vi' or some other text editor.
See 'man sh' (or ksh, csh or bash) for more information about the functionality
of the shell.
Once you have created your shell script, you set the execute permissions
using the chmod ('change mode') command:
You can then run the script by typing its name:3) How do I change my password?
4) What is my 'home directory'?
/home/foobar
/home/foobar/CS208/cw1
5) How do I list my files?
ls bin
ls -l
ls -l bin
6) How do I move to another directory?
cd bin
cd ..
7) How do I create my own sub-directories?
mkdir CS208
mkdir CS208/cw1
cd CS208
mkdir cw1rmdir CS208/cw1
rmdir CS2088) How do I delete files?
rm oldfile
rm *
rm tmp/*9) What is a Unix shell?
10) What is a shell script?
cat >myscript
rm ~/logfile.old
mv ~/logfile ~/logfile.old
touch ~/logfile
^Dchmod u+x myscript
Name | Command | Initialization files |
---|---|---|
Bourne shell | sh | .profile |
C Shell | csh | .login and .cshrc |
Korn shell | ksh | .profile and any file specified by the ENV environment variable (conventionally .kshrc) |
Bourne-Again shell | bash | .bash_profile, .login, and .bashrc |
Unix FAQ
A collection of frequently asked questions from Unix-related Usenet newsgroups.
http://www.cis.ohio-state.edu/hypertext/faq/usenet/unix-faq/top.html
Unix History
A very brief look at Unix history.
http://www.faqs.org/faqs/unix-faq/faq/part6/section-2.html
A Short Bibliography of Unix Books
Useful summary of good UNIX references with brief comments on quality.
http://ugrad-www.cs.colorado.edu/unix/bibliography.html
On the Design of the UNIX operating System
Article, published in 1994, on why UNIX was so successful. Interesting glimpse of history.
http://www.hillside.co.uk/articles/typing.html
Virtually Unix
Applying UNIX tools to Windows95.
http://virtunix.itribe.net
UNIX Commands
A list of UNIX commands by their function (e.g., file commands, directory commands, printing commands).
http://www.cheme.cornell.edu/Computers/unixcmds.html