UNIX NOTES Page 5

UNIXÔ/Linux Notes: Professor: Michael P. Harris

v.20051201

UNIXÔ is a multi-user, multi-tasking operating system originally developed at AT&T Bell Laboratories. It provides programs for editing text, sending electronic mail, preparing tables, performing calculations and many other specialized functions that require separate application programs in other operating systems. One of the key identifying features of UNIX is its standardized directory and file structure.

Typical UNIX/Linux root /

Directory structure: │

┌────┬────┬────┬────┬───────┬┴────────┬───┬───┬───┬────┐

bin etc dev mnt lib lost+found home tmp sys boot unix

│ │ │

default │(mounted ┌────┬────┬─┴───┬───┬───┬────┐

┌───┬┴──┐volumes) mike teri ... etc bin lib spool

hd0 fd0 sd0 (users home directories)

There are many different versions of UNIX. One of the most important is the line of UNIX releases that started at AT&T, the latest being System V Release 4. Other important UNIX versions have come from the University of California at Berkeley; the latest is called BSD. Microsoft’s Xenix, a early popular microcomputer implementation of UNIX was originally based on an earlier AT&T release called System V. Linux is currently the leading popular “Open Source” implementation of a Unix-like standard operating system. POSIX is the validation standard, set for UNIX-like operating systems. Starting with Windows 2000 Pro, Windows 2000, XP, and 2003 are all now POSIX compliant. Other major versions of UNIX include SunOS, Solaris, SCO UNIX, AIX, HP/UX, ULTRIX, NOVELL UNIX (Univel), and the various implementations of the popular Linux OS.

Since it started more than 35 years ago, UNIX has grown and changed in a different way from most operating systems. Many early UNIX users were computer and scientific professionals; more than a few of them extended UNIX by adding tools and functionality to do what they needed. UNIX was also used to develop a lot of the powerful networking systems that connect the world, such as Internet. So, whereas most operating systems were typically developed and controlled by one corporation, UNIX has been developed through a collective effort. This has meant more versions and somewhat more confusion than "standardized" operating systems like MSDOS & Windows. But it has also helped to make UNIX the flexible and incredibly rich and powerful operating system that it is today.

UNIX and its derivatives were not designed as "user-friendly" operating systems, in fact, UNIX has, in the past, earned its label of "user-hostile." UNIX can be used the way it was originally designed, on typewriter-like terminals (ttys). Most modern versions of UNIX can also work with window system GUIs (Graphical User Interface) which allow each user to have more than one "terminal" on a single display. The X Window System (called X for short) is the most common UNIX window system. The appearance of X Windows may vary between systems due to different window managers. Four of the most common window managers are mwm (Motif Window Manager), olwm (Open Look Window Manager), CDE (Common Desktop Environment) and the new Linux windows shells Gnome, KDE, fluxbox, and others.


Getting Started:

UNIX can be overwhelming with its barrage of details. To get started though, all you need to do is master just a few details:

o How to Log in and out of your system

o Understand the Shell and how to control the system with control characters

o Learn the important UNIX specific directories and files

o Manage UNIX files and directories, including listing, creating, copying, printing and removing files, and moving in and out of directories

o Work efficiently using UNIX pipes, filters, and multi-tasking.

Logging In:

Before you can start using UNIX and its facilities, the System Administrator has to set up a UNIX account for you with your login name, password, and home directory. At many sites, there will be a whole network of UNIX computers so you may also have to know the hostname of the computer that has your account as well. When you turn on your terminal you should see a message from the UNIX computer that looks something like:

login:

Logging in is the process of making your self know to the UNIX computer and getting into your account. On remote systems you will need to run a remote login program like telnet, rlogin, cu, or tip. In this case your login session might look similar to the following: (what you type is in bold)

telnet mercury.delmar.edu

Sun Solaris OS

mercury.delmar.edu: Solaris UNIX version 9.00.10

login: mpharris

Password: ********

Last login: Wed Nov 28 14:34 CST 2005, from mercury.delmar.edu

motd: The "crisis" of Today is the "joke" of Tomorrow

REMEMBER !!!

We will be shutting down at 4:30pm for system backups.

Fri Dec 2 12:24:48 CST 2005

$_


UNIX NOTES Page 5

The UNIX Shell:

Once you've logged into a UNIX computer, you're working with a program called the shell. The shell interprets the commands you enter, runs the program you've ask for, and generally coordinates what happens between you and the UNIX operating system. There are four shells in common use: the Bourne shell, Korn shell, Bash and C shell. For the novice the differences are slight however some to run some software or execute some program (especially shell scripts) you will need to know which shell you are using (ask your system administrator). The only immediate difference you will see is that the Bourne, Korn, and Bash shells prompt you with $_ while the C shell most often uses %_ as the prompt. Certain keyboard commands (keystrokes) are interpreted by the shell, these are commonly called control characters. The basic control characters are:

Ctrl-C or [DEL] Interrupt character (interrupts or cancel a command)

Ctrl-D Returns you to UNIX command level. Used to signal end of input. ** Also logs you off of most UNIX systems

Ctrl-H or [BACKSPACE] Erase character to left of cursor

Ctrl-Q Restart output after paused by Ctrl-S

Ctrl-S Pauses output to the screen

Ctrl-U Erase the whole input line so you can start over

UNIXÔ vs. MSDOSÔ

The UNIX operating system has been around much longer than MSDOS. While MSDOS owes much of its original heritage to a single-user operating system named CP/M, MSDOS evolved gaining more and more UNIX like capability. MSDOS is not case sensitive meaning that commands can be typed in either upper or lower case and MSDOS treats them all as if they were typed in UPPER CASE. UNIX is case sensitive meaning that there is a difference between a command typed in upper or lower case. The UNIX standard is that commands are typed in lower case. A brief comparison of MSDOS and UNIX command equivalents follows:

CD pwd

CD DIRNAME cd dirname

CHKDSK fsck

COPY FILE1 FILE2 cp file1 file2

COPY FILE1 + FILE2 FILE3 cat file1 file2 >file3

COPY FILENAME PRN pr filename | lpr

DIR ls

DIR /W ls -C

DIR /P ls | more

DEL FILENAME rm filename

MD DIRNAME mkdir dirname

REN FILE1 FILE2 mv file1 file2

RD DIRNAME rmdir dirname

TYPE FILENAME cat filename


File Access and Permissions

An important point to always remember is that in UNIX everything is a file. The textbook definition of UNIX usually goes something like this...

UNIX - a multi-user/multi-tasking interactive operating system developed by AT&T. UNIX has a directory structure that is tree-like with files containing all the information that is part of the system.

Most people familiar with microcomputers and MSDOS are familiar with the tree-like directory structure with directories, sub-directories and pathnames. But in UNIX the directory structure and file system is the heart of the system. UNIX is also device independent --there for no duplication of commands is necessary for different devices such as the screen, printer, or disk drives.

For example, UNIX always keeps the files in its directory structure is a sorted order, there for to rename a file is really moving that file within the directory structure. To copy that file to another directory, to the screen, or to a floppy disk drive is the same command because UNIX is device independent, everything is a file, the destination directory, the screen, the auxiliary storage device are all files to UNIX. This concept may take a little getting used to before all that is means sets in.

To log into a UNIX system your terminal must be described to the system. In the directory /dev the system device files (files that contain the hardware interfacing information UNIX needs) are contained. In addition, your terminal type is stored in /etc/ttytype, your terminal speed in /etc/ttys, and your terminal setup and capabilities data in /etc/termcap. The advantage of this system is obvious, if you change your terminal or enhance its capabilities, your just edit the system files. In addition you can have multiple definitions and settings for multiple different users.

The UNIX executable commands are kept in the /bin directory with miscellaneous system data files kept in the /etc directory. UNIX commands are usually short and terse and most always in lower case. UNIX filenames may include A-Z, a-x, 0-9, . and _. After UNIX boots from the kernel code stored in /unix directory, the /etc/rc startup file is executed. This (reboot cold) startup file would be the equivalent of the MSDOS CONFIG.SYS and AUTOEXEC.BAT files. The system default setup information is stored in the /etc/default file.

When users log into a UNIX system, there access is controlled by password and access information stored in the /etc/passwd and /etc/group files. Once logged in users are met by the users login message-of-the-day stored in the /etc/motd file and then the users personal startup and setup commands are executed from their own private .profile file stored in their /home/username login/home directory.


UNIX NOTES Page 5

One logged into the UNIX system file access is controlled by the standard UNIX permissions: r w x -. The permission settings are for read, write (or change), eXecute, and permission denied (-). The permissions are grouped into a set of three rwxrwxrwx where the first three are the permissions for the user/owner of the file, the second three are the permissions for members of the group assigned to the file and the last three permissions are for all others who may wish access to the file. The command chown is used to change the owner of the file. The command chgrp will change the group assigned to the file. And the command chmod (for change access mode) will change the file permissions. Of course, you must have write permission to change the owner, group assignment, or permissions to a file.

As an example, assume the ls command (list single file) gave you the following permission settings for the file /etc/motd... rwxr-x--x

These permission settings would indicate that the owner (usually supervisor) has Read, Write, and eXecute permissions to the file. Those who have the assigned group access permissions can Read and eXecute the file, all others may only eXecute the file.

When changing permissions to your files with the chmod command, you have the options of a, u, g, and o (for All, User/owner, Group, and Others) the syntax is:

chmod options filename

where options can include:

(1) a, u, g, o (2) + or - and (3) r, w, x in any combination.

For example: chmod g+rx myfile would add Read and eXecute to the group portion of the permission settings.

Alternate Input / Output, Piping, and Redirection

The Unix commands for redirecting Input and Output are:

> redirect output < redirect input

>> redirect output append << redirect input append

| pipe (output into input) tee split output into two streams

For example: who | sort > wholist

would execute the who command (generate a list of who is currently logged on to the system) and pipe the output into the input of the sort command (alphabetize) and the sorted list would be written to the file wholist.

and... banner < wholist >> register

the file contents of wholist would be fed into the command banner (which generates large bannerized letters from file contents) and add this output to the end of the file register.


UNIX NOTES Page 5

UNIX DIRECTORY GUIDE

Typical UNIX/Linux root /

Directory structure: │

┌────┬────┬────┬────┬───────┬┴────────┬───┬───┬───┬────┐

bin etc dev mnt lib lost+found home tmp sys boot unix

│ │ │

default │(mounted ┌────┬────┬─┴───┬───┬───┬────┐

┌───┬┴──┐volumes) mike teri ... etc bin lib spool

hd0 fd0 sd0 (users home directories)

/ UNIX root directory

/bin UNIX Commands (binary files)

/boot UNIX file system bootstrap loader programs

/etc miscellaneous system data files

/etc/default system default setup files

/dev peripheral device control files

/lib libraries for the 'C' compiler

/lost+found depository for misplaced files

/mnt empty directory to mount file systems

/sys code for UNIX kernel (operating system)

/tmp temporary files (may be auto deleted)

/home users master/personal directory (or /usr, or /user)

/ home /bin more commands usually user created

/ home /lib more language libraries and data files

/ home /spool print spooler master directory

/ home /tmp users temporary files

/ home /asm administration accounting files

/unix executable code for UNIX kernel



UNIX NOTES Page 5

UNIX FILE GUIDE

. name of current directory

.. name of current directory's parent

.profile set up environment at login (personal startup file)

/etc/group designate group 'names'

/etc/logbook logbook of installed software

/etc/motd (message of the day) login message for users

/etc/passwd define system users and access

/etc/rc define system initialization and startup commands

/etc/systemid define system name

/etc/termcap define standard terminal setup information and capabilities

/etc/ttys define terminal port status/speed

/etc/ttytype define default terminal type

/home/lib/crontab time & date for auto execution

/home/adm/messages record of console messages

Sample UNIX / home directory with subdirectories:

/

home

┌─────────────┬──────────────┬┴─────────────────┬─────────┐

adam betty edward mark ...

│ ┌───┼────┐ ┌──┴─┬────┐ ┌─────┴┬────┬────┐

├demo1 memo etc letter util fax pgms news bin fax make

└demo2 │ │ │ │ │

├mm1 ├let1 ├fax1 ├jan ├mod1.c

└mm2 ├let2 └fax2 ├feb └mod2.c

└let3 └mar

All users have a personal .profile file in /home/username/.profile



UNIX NOTES Page 5

ALPHABETICAL LIST OF UNIX COMMANDS

The commands in the Basic System are listed below in alphabetical order.

asktime set system date and time

assign assign a device to a user

at execute commands at a later time

atq examine the "at" job queue

atrm remove a job from the "at" job queue

awk pattern scanning and processing language