Introduction to UNIX Computing at SHSU
This document is intended for general users of systems using the UNIX
operating system, and its objective is to introduce basic UNIX concepts
and commands to the reader. The % and $ symbols represent
commands or shell prompts, and arguments inside of brackets indicate that
something needs to be typed (without the brackets). For example [name]
would imply that you need to type your name in that space, and [return]
indicates that you should press the Return key. Text in monospace font
is what is actualy displayed on the screen.
UNIX is an operating system that:
was developed by AT&T Bell Laboratories in 1969, and has become recognized
as the standard operating system around the world by such standards committees
as Open Software Foundation and UNIX International;
is a collection of small programs that each does one job very well. Combined,
these programs make powerful tools, showing that "...the power of a system
comes more from the relationships among programs than from the programs
themselves." (Kernighan and Pike)
is written mostly in C and is well known for its portability. VAXs, Sun
workstations , IBM RS6000s, PCs, and some IBM mainframes can all run UNIX.
This high degree of machine independence makes moving applications from
one computer to another fairly easy. Portability is the main reason UNIX
has become the standard operating system.
is an interactive system that is multi-tasking and multi-user. In other
words, users can run jobs "in the background" while moving on to other
projects, and they can share information, files, and utilities easily with
UNIX System Components
The kernel is a program that manages the resources of a UNIX system.
It keeps track of peripheral devices (printers, terminals, etc.), schedules
jobs, and provides a file system that manages long-term storage of data
files. Basically, it is the operating system.
The shell is a command interpreter that acts as an interface between
the user and the operating system. It is not part of the operating system,
but it translates your requests into actions for the kernel; it is a program
that runs under UNIX.
You can use the shell interactively and in script files. It can also be
programmed, which makes for a very powerful tool.
There are three major shells running on UNIX systems: the C Shell (csh;
best for interactive use), the Bourne Shell (sh; used mostly for shell
programming), and the Korn Shell (ksh; used for both interactive and shell
programming on some systems, e.g., AIX). By default, most systems use the
C Shell for command interpreting.
- tcsh is a derivative of csh
- bash is a derivative of sh
- zsh is a derivative of sh
Directories are useful for organizing files in a structured manner,
much like folders containing documents in a file cabinet. To make a directory
type mkdir [dirname]. Subdirectories can be made in the directory
using the same command. Type cd [dirname] to change your present
working directory to [dirname]. To create a subdirectory, type
UNIX has a hierarchical directory structure that is comparable to an
upside-down tree, with the root directory at the top,symbolized by the
slash (/). Directories can be considered the branches of the tree,
while files can be thought of as the leaves.
In UNIX it is possible to have the same filenames for files in different
locations on the system. For this reason, you can specify filenames by
including directory names of where the file "lives"; this type of filename
is called a pathname, and each directory is separated by a slash (/).
For example, the file program1 might exist on two directories
but contain different information:
These filenames are called absolute (or full) pathnames because they can
be traced from root and begin with a slash. Sometimes it is more convenient
to specify a pathname relative to your present working directory. This
type of pathname is called a relative pathname and does not begin with
a slash. For example, when Sue is in her home directory (/home/sue),
the relative pathname of the file program1 is class/program1.
A dot (.) represents the current directory (the directory you
are presently in). When Sam is in his cis290 directory, the
directory can be referred to as /programs. Two dots (..)
refer to the next directory level up, or the parent directory. If Sue is
in /home/sue, and she wishes to move to /home, she may
enter the command cd ..
Logging In To UNIX
The university provides unx1.shsu.edu as a generally accessible
UNIX system for faculty and students at Sam Houston State. The general
way to login to a UNIX computer (Note: UNIX is case-sensitive and uses
mostly lowercase. Do not login in uppercase!):
Remote login from an inter-networked computer (e.g., a workstation, a VAX):
telnet [machine_name] [return] (where machine_name is the
hostname of the remote system) or rlogin [machine_name] [return]
(see console login: prompt below)
From the console: login: [userid] [return] (where userid is your
login name, i.e., abc1234) Password: [your_password] [return]
To see the files in the current directory use the ls command:
% ls [return]
For Sam to get a list of the files in his cis290 directory while
in his home directory, he could type:
cis290 file1 file2
% ls cis290 [return]
Sue can get a long listing of all files in her current directory using
the option -l:
% ls -l [return]
The first line, total 32, gives the total amount of disk usage
in blocks. The rest of the output gives information about each file in
the directory. The first character on the line tells you what type of file
it is: a - is a normal file and a d means that it is
a directory. The remainder of the first of seven fields relates to file
drwxr-xr-x 2 sue other 512 Oct 26 10:16 class
-rw-r--r-- 1 sue other 4348 Dec 21 17:01 program1
Files that begin with a dot are called hidden files because they are
not normally shown when using ls. Some common hidden files are:
.profile, which is read upon login when using the Bourne or Korn
shells; .login and .cshrc, both interpreted by the C
shell upon login; and .bash_profile and .bashrc are bash
startup files. Use ls -a to list all your files:
% ls -a [return]
The current directory, ., and the parent directory, ..,
are also shown.
. .. .bashrc .bash_profile class program1
The simplest way to view a file is to use the cat command:
If you have a longer file to view use the more or pg
commands, which work similarly in that they both display one screen of
text at a time:
% cat [file_name] [return]
Using the cat command is quite convenient if file_name
is a short file.
For both more and pg, a q will quit paging and
return to the command prompt.
% more [file_name] [return]
Moving and Renaming Files
Moving and renaming files is done with the mv command. For
instance, Sam could move the file program1 from his home directory
to his cis290 directory, where it will keep the same filename:
As another example, Sue could rename pgm.c to old_pgm.c:
% mv program1 cis290 [return]
Note that mv actually removes the original file and moves it.
% mv pgm.c old_pgm.c [return]
The command for copying a file, cp, is similar to using the
mv command. Sam could make a copy of the file program1
and call it project1:
To copy pgm.c, currently in her home directory, to her programs
directory and call it the same thing, Sue would issue the following command:
% cp program1 project1 [return]
This would create a file called /home/sue/programs/pgm.c.
% cp pgm.c programs [return]
To remove a file on UNIX use the rm command. For example,
if Sue wanted to remove the file pgm.c from her home directory
she would use the rm command:
In UNIX, the only way restore a file is from a tape or disk backup, so
many users prefer to use the interactive option, -i, when using
the rm command; only by responding with a y will it delete
% rm pgm.c [return]
% rm -i pgm.c [return]
pgm.c: y [return]
Other Basic UNIX Commands
In addition to the commands mentioned above, here are some other UNIX
commands that you may find useful:
cal [month] [year]: Print a calendar. (cal 2 1998 will
print the month of February 1998)
chmod [#]: Change mode (file permissions) on file(s) and/or directory(s).
date: Print current time and date.
echo: Echo arguments to the screen.
exit, logout: Terminate session.
finger [last_name]: Provide user information.
grep [string] [search_area]: Search for a string or regular expression.
(grep path .cshrc will find all occurrences of the word path
in the file .cshrc).
passwd: Change password. (Prompts for information)
pwd: Print information on the working directory.
rmdir [dir_name]: Remove directory.
who : Who is logged in on the system.
Any additional information that you may need on UNIX commands can be
found in the on-line UNIX Reference Manual. Type:
where [command] is the command in which you are interested. The
command man ls, for example, will show you the portion of the
manual that deals with the command ls. Also, man -k keyword
most UNIX systems enables you to find the man page(s) that have keyword
in their titles, such as man -k perl.
% man [command] [return]
Modified September 10, 2000