A Quick Look at the Unix Operating System
What is an Operating System?
An operating system
is a program that provides an interface between hardware and users
... and so much more.
Hardware Examples
- I/O devices (e.g., keyboard, mouse, printer)
- CPU
- Main memory
- Secondary storage (e.g., hard disk, floppy disk, CDROM)
Examples of Operating Systems
- MS-DOS and Windows 95/98/NT/2000
- MacOS
- PalmOS
- Unix: comes in lots of flavors
- AIX (made by IBM)
- Solaris (made by Sun Microsystems)
- Unicos (made by Cray)
- IRIX (made by Silicon Graphics Inc)
- HP-UX (made by Hewlett-Packard)
- Linux (freeware that runs on PCs and other platforms)
What is Unix?
- Developed in the late 1960s/early 1970s at Bell Labs.
- Cryptic: most command names are 2 - 5 characters long.
- Text based like MS-DOS (because it's so old),
not window based like Win98 or MacOS.
- Very efficient, powerful, reliable.
- Common in academic and research environments.
- Different flavors (e.g., Linux, AIX, IRIX)
are not fully compatible
but often are mostly compatible.
- Designed for people who already know everything about Unix.
Files & Directories
Unix files and directories are very much like files and directories
(folders)
in Windows and MacOS.
Basic Commands
All commands must be typed exactly right,
or they will fail
(or do something other than what you want).
Unix is case sensitive;
it matters very much whether a letter is upper case (capital)
or lower case (small).
- man command
Display the online documentation for a command.
For example,
man pwd
displays the online documentation for the command pwd.
man -k word
gives a listing of all the commands related to word.
- date
Today's date and time.
- pwd
Print the name of the current (working) directory.
In MS-DOS, by contrast,
the current directory is included in the prompt:
C:PROGS\MYPROGS>
- cd direc
Change the current directory to a directory named direc.
Like cd in MS-DOS.
- ls
List the files and subdirectories in the current directory.
Like dir in MS-DOS.
You can get a more detailed listing of the current directory's contents:
ls -l
- mv srcfile dstfile
Move the file named srcfile
to a file named dstfile
(i.e., change its name).
You can also use mv to move a file from one directory to another:
mv srcfile dstdirec
Like move in MS-DOS.
- cp srcfile dstfile
Copy a file named srcfile to a new file named dstfile
(or, if dstfile already exists,
replace its contents with the contents of srcfile).
Like copy in MS-DOS.
- rm thisfile
Remove (delete) a file named thisfile.
Like del in MS-DOS.
- mkdir newdirec
Make a new directory called newdirec
as a subdirectory of the current directory.
- rmdir olddirec
Remove an empty subdirectory named olddirec.
- cat thisfile
Output the contents of the file thisfile
to the terminal.
cat srcfile1 srcfile2 > dstfile
Concatenate the contents of srcfile1 and srcfile2
(dump them out one after the other)
and put the concatenated output into dstfile.
- more thisfile
Output thisfile to the terminal
in a controlled way.
- time command
Determine how long it takes to run a command.
- mailx hneeman@ou.edu
Send e-mail to hneeman@ou.edu.
Redirecting I/O
Instead of input coming from the keyboard
or output going to the terminal,
they can be redirected
from or to a file.
- program > outputfile
The output of executing program
goes into outputfile.
- program < inputfile
The input needed for executing program
come from inputfile.
- program < inputfile > outputfile
The input needed for executing program
come from inputfile,
and the output
goes into outputfile.
- program >> outputfile
The output of executing program
is appended to the end of outputfile.
Root Directory
The root directory
(which is denoted by a slash /)
is the topmost directory;
all other directories are subdirectories of it.
It's like the "My Computer" icon in Windows 98/NT,
or like the desktop in MacOS.
Directory Paths
The full name of a directory, starting from the root,
is called a path.
The full name of a file is its path, a slash and its filename.
So,
if a user
neeman
has a home directory
/tmp_mnt/ecn/facstf1/neeman
in which there's a subdirectory
CS1313,
and in the CS1313 subdirectory
is a file named
mynumber.f90,
then the path of
mynumber.f90
is
/tmp_mnt/ecn/facstf1/neeman/CS1313
and the file's full name is
/tmp_mnt/ecn/facstf1/neeman/CS1313/mynumber.f90
Special Directories
- The root directory is denoted with a slash:
/
- The home directory of a user named neeman is denoted
~neeman
- You can denote your own home directory as
~
- The current directory is denoted with a single period:
.
- The parent directory of the current directory
is denoted with two periods:
..
Wildcards
Asterisks indicate parts of a filename that could be anything.
- *.f90
Every file that ends in .f90
- *number*
Every file that contains number somewhere in its filename
- [a-z]*
Every file whose filename starts with a lower case letter
File Permissions
The person who owns a file gets to decide
who can read it,
who can write to it,
and, if it's an executable, who can execute (run) it.
- User permission:
what you as the owner are allowed to do with it.
- Group permission:
what people like you
(e.g., other students)
are allowed to do with it.
- Other permission:
what people who aren't like you
(e.g., faculty)
are allowed to do with it.
- Superusers:
some people (typically the people in charge of administering the
computer you're on)
have a special status called superuser
that allows them to read, write and execute files
even if they're not supposed to have permission.
- Executing a directory:
if a directory has execute permission for you,
then you can go into it.
- chmod
Change mode:
change the permissions on a particular file or directory.
See the man page for details.
References:
Paul DuBois,
Using csh & tcsh.
O'Reilly & Associates, 1995.
Daniel Gilly,
Unix in a Nutshell, System V edition.
O'Reilly & Associates, 1992.
Rebecca Thomas & Jean Yates,
A User Guide to the Unix System.
Osborne/McGraw-Hill, 1982.