UNIX OVERVIEW
-
An operating system for workstations; used by scientists and
software developers.
-
Computing Science students at Malaspina have access to a DEC Alpha
running Unix.
-
DOS started as a simplified version of UNIX; there are still
many similarities.
-
Note that all names (names of files and command names) are
case-sensitive in Unix. E.g.
myfile myFile
are two different files. Almost all command names are written
entirely in lower-case.
-
There are several command interpreters available with Unix.
The common possibilities are: sh, csh, ksh, and tcsh.
They are called `shell' programs (or `command shells'), because
they enclose the operating system and protect it from users
(and vice versa).
FILE SYSTEM
-
Files represent regions on the hard disk(s) that hold data
and programs.
-
The operating system provides a naming scheme for files;
the names are collected together in directories.
-
A UNIX directory may hold ordinary files, and other directories.
-
The directories refer to each other in a pattern that is close
to being a tree. (Interior nodes are directories; leaf nodes
are ordinary files.)
-
Every directory has two special entries:
- ..
- refers the the parent directory
- .
- refers to the current directory
-
Directories are themselves files, but the information inside them
has a special format, and a `mode bit' is set to flag the file
as being a directory.
LISTING DIRECTORIES and PATHNAMES
-
The ls command (with no arguments)
lists the contents of the current directory.
-
Relative pathnames provide access to files in other directories
than the current directory. E.g.
Dir1/prog
references a file where Dir1 is a member of the current
directory, and Dir1 is a directory which holds a file named
prog.
The slash character / is used as a separator between
components of the pathname.
(Analogous to DOS \.)
-
A relative pathname defines a path through the file system that
starts at the current directory.
-
There is a root directory which is the root of the file system
tree. Its name is /.
-
An absolute pathname defines a path through the file system that
starts at the root of the entire file system tree. It begins
with a leading slash character. E.g.
/usr/bin/cc
is an absolute pathname.
-
The ls command can be used with a directory name argument. E.g.
ls /
lists the contents of the root directory.
HOME DIRECTORY and CURRENT WORKING DIRECTORY
-
Every user should have a home directory. This is where you
start immediately after logging in. I.e. your `current working
directory' is initially your home directory.
-
The cd command changes the current working directory. E.g.
cd Dir1
changes your current directory to be Dir1.
-
To return to your home directory, just type the command
cd
-
To visit another user's home directory, you can type a command
like this
cd ~sue
to visit user `sue', provided that your command shell is csh.
COMMANDS
-
Commands come in three flavours:
- they can be built-into the shell
(cd is such an example);
- they can correspond to executable programs
(e.g. the ls command causes the program
/bin/ls to be executed);
- they can be shell script files (files that contain lists
of commands to execute).
-
The shell has a search path for finding executable programs.
The search path is just a list of directories. You can see what
your search path is by typing
echo $path ## csh only
or
echo $PATH ## all shells
SOME USEFUL COMMANDS
- cat [ file1 file2 ... ]
-
displays the named files on the screen one after the
other without stopping
- more filename
-
displays the named file on the screen, one screenful at
a time. (Hit space to see next screenful.)
- date
-
outputs current date and time
- fmt [ filename ]
-
formats an ASCII text file so that lines are close to
but no longer than 72 characters.
- wc [ filename ]
-
outputs line count, word count and character count in
the provided input.
I/O REDIRECTIONS
-
The default behaviour of most commands is to read input from the
keyboard and send output to the screen.
-
The input source of a program is called its `standard input';
similarly the output destination is its `standard output'.
-
The output of a command can be directed to a file with
>. E.g.
date > file1
-
The input to a command can be redirected to come from a file with
<. E.g.
wc < myTextFile
-
Most commands that read their standard input also have an
optional file name argument. E.g.
wc myTextFile
works much like the preceding example. However it is the
wc
program that reads the file in this case; it is the command
shell program that reads it in the earlier example.
VARIATIONS OF THE LS COMMAND
- ls -l [ DirectoryName ]
-
produces a long listing of names of files in the
specified directory. The info includes owner, file
size, date/time of last change, access permissions.
- ls -R [ DirectoryName ]
-
produces a recursive listing of specified directory and
all its subdirectories.
- ls -F [ DirectoryName ]
-
adds an extra character after filenames to show
special characteristics. A slash indicates a
directory, an asterisk shows a file with execute
permissions set.