back to cis 15

UNIX

What is Unix                            

Getting started                                    getting started excercises

Unix file system                                    file system excercises

Unix Editors

Editing command line

Printing

Compiling programs

Unix shells                                             shell excercises

shell scripts

Commands list


 

What Is UNIX?

·         UNIX is a computer operating system.

 

·         An operating system is the program that controls all the other parts of a computer system, both the hardware and the software. It allocates the computer's resources and schedules tasks. It allows you to make use of the facilities provided by the system. Every computer requires an operating system.

 

·         UNIX is a multi-user, multi-tasking operating system. Multiple users may have multiple tasks running simultaneously. This is very different than PC operating systems.

 

·         UNIX is a machine independent operating system. Not specific to just one type of computer hardware. Designed from the beginning to be independent of the computer hardware.

 

·         UNIX is a software development environment. Was born in and designed to function within this type of environment.

 


History of UNIX

·         1969: Developed at AT&T Bell Labs by Ken Thompson and Dennis Ritchie.

·         Created in an environment when most computer jobs were fed into a batch system (running single jobs, using punch cards and waiting for output).

Developed as a response to the frustration of programmers who needed a set of computing tools to help them with their projects and their collaborators. Allowed a group of people working together on a project to share selected data and programs.

·         Unix was originally written in assembly language, thus moving Unix from one computer to another involved a large amount of rewriting of the programs constructing Unix.

·         1973: Thompson and Ritchie successfully rewrote Unix in C , making it a portable operating system.

·         1975: AT&T makes UNIX widely available - offered to educational institutions at minimal cost. Becomes popular with university computer science programs. AT&T distributes standard versions in source form: Version 6 (1975), Version 7 (1978), System III (1981).

·         1984 to date: University of California, Berkeley adds major enhancements, creates Berkeley Standard Distribution (BSD)

·         1984 to date: Many Berkeley features incorporated into new AT&T version: System V

·         UNIX has become the operating system of choice for engineering and scientific workstations.

·         Two variations maintain popularity today, AT&T System V based and the Berkeley Standard Distribution.

 


UNIX Philosophy

·         Make each program do one thing well. Reusable software tools:      1 tool = 1 function

·         Enable the output of one program become the input of another, to combine simple tools to perform complex tasks

·         Prototyping: get something small working as soon as possible and modify it incrementally until it is finished

·         Use short commands and messages: reduces typing and screen output

·         Upgrade Unix by writing your own functions and incorporate them into Unix


Why UNIX?

·         Hardware independence

o        operating system code is written in C language rather than a specific assembly language

o        operating system software can be easily moved from one hardware system to another

o        UNIX applications can be easily moved to other UNIX machines. Porting is usually as simple as transfer of the source and a recompile

o        Device-independent I/O operations, Unix treats al devices as files allowing redirection

 

·         Productive environment for software development

o        rich set of tools

o        versatile command language

·         UNIX is available at virtually all computing centers, allowing researchers relative ease in utilizing the facilities at each center.

·         Multi-user and multi-tasking capability

·         Hierarchical file system providing easy management

·         More than 100 utilities 

 


 

UNIX Components

·         Kernel

o        The core of the UNIX system. Loaded at system start up (boot). Memory-resident control program.

o        Manages the entire resources of the system. Provides service to user applications such as device management, process scheduling, etc.

o        Example functions performed by the kernel are:

§         managing the machine's memory and allocating it to each process.

§         scheduling the work done by the CPU so that the work of each user is carried out as efficiently as is possible.

§         accomplishing the transfer of data from one part of the machine to another

§         interpreting and executing instructions from the shell

§         enforcing file access permissions

o        You do not need to know anything about the kernel in order to use a UNIX system. These details are provided for your information only.

·         Shell

o        Is an interface, whenever you login to a Unix system you are placed in a shell program. The shell's prompt is usually visible at the cursor's position on your screen. To get your work done, you enter commands at this prompt.

o        The shell is a command interpreter; it takes each command and passes it to the operating system kernel to be acted upon. It then displays the results of this operation on your screen.

o        Several shells are usually available on any UNIX system, each with its own strengths and weaknesses.

o        Different users may use different shells. Initially, your system administrator will supply a default shell, which can be overridden or changed. The most commonly available shells are:

  

§         Bourne shell (sh)

§         C shell (csh)

§         Korn shell (ksh)

§         TC Shell (tcsh)

§         Bourne Again Shell (bash)

o        Each shell also includes its own programming language. Command files, called "shell scripts" are used to accomplish a series of tasks.

·         Utilities

o        UNIX provides several hundred utility programs, often referred to as commands.

o        Accomplish universal functions

§         editing

§         file maintenance

§         printing

§         sorting

§         programming support

§         online info

§         etc.

o        Modular: single functions can be grouped to perform more complex tasks


Other Unix systems

·       AIX – IBM’s version of Unix

·       Linux – a variant of the Unix operating system, designed to run on personal computers. Shares many features of Unix system V

·       Solaris – by Sun Microsystems, based on systems V and BSD, used in the atrium lab.

 

 


Logging On To The System

·         Before you can begin to use the system you will need to have a valid username and a password. The System Administrator or a “Computer Accounts” office typically handles assignment of usernames and initial passwords.

·          You will be given a sheet with your username, which is usually your name’s initials (rharpaz), and a password, which is computer-generated sequence of 8 characters (Ejh5Y7*!).

·         To login to your account

1.     Type your username at the login prompt. UNIX is case sensitive. When the password prompt appears, type in your password. Your password is never displayed on the screen as a security measure. It also is case sensitive.

·         What happens after you successfully login depends upon your system:

o        Many UNIX systems will display a login banner or "message of the day". Make a habit of reading this since it may contain important information about the system.

o        Other UNIX systems will automatically configure your environment and open one or more windows for you to do work in.

o        You should see a prompt - usually a percent sign (%) or dollar sign ($). This is called the "shell prompt”. It indicates that the system is ready to accept commands from you.

o        At the Atrium lab the first thing you will have to do is change your password and wait 25 minutes for the system to process it. The password must be between 6-8 characters long and remember it is case sensitive.

 


 Your Home Directory

·         Each user has a unique "home" directory. Your home directory is that part of the file system reserved for your files.

·         After login, you are "put" into your home directory automatically. This is where you start your work. example : $ acc6:/users3/user_name>

·         You are in control of your home directory and the files, which reside there. You are also in control of the file access permissions (discussed later) to the files in your home directory. Generally, you alone should be able to create/delete/modify files in your home directory. Others may have permission to read or execute your files as you determine.

·         In most UNIX systems, you can "move around" or navigate to other parts of the file system outside of your home directory. This depends upon how the file permissions have been set by others and/or the System Administrator, however.


 Using UNIX Commands

·         UNIX commands are executable files and built-in utility programs

·         All UNIX commands are case sensitive. Most commands are in lower case.

·         Commands typically have the syntax:

 
            command   - option(s)   argument(s) 
     

·         Options

1.     Modify the way that a command works

2.     Usually consist of a hyphen followed by a single letter

3.     Some commands accept multiple options which can usually be grouped together after a single hyphen

4.     A small number of commands require each option to be given separately

5.     Should be separated from the command name by a space

·         Arguments

1.     Most commands are used together with one or more arguments

2.     Some commands assume a default argument if none is supplied

3.     Arguments are optional for some commands and required by others

4.     In most cases, multiple arguments should be separated from each other by a space. They should be separated from the command name and/or options by a space also.

 

 

·         Examples

1.     To use a command with no argument: the "date" command displays the current time and date.

              date 
 

2.     To use a command with a single argument: the "cd" command changes to the directory of its argument, newdir

            cd newdir 
 

3.     To use a command with both an option and an argument: the wc command counts the number of words, characters, and lines in a file. By using a different option you can choose what is counted.

 
     wc -w file1     counts the words in file1 
     wc -c file1     counts the characters in file1 
     wc -l file1     counts the lines in file1 
          

4.     To use a command with several arguments: the cat command takes the names of three files as arguments. It displays contents of file1 followed by file2 and then file3.

    
      cat file1 file2 file3 

5.     To use a command with multiple options and default argument: the ls command provides a long (l) listing of      all (a) files and also shows the file size (s). Because no argument is specified, the default argument (current directory) will be used.

             ls -als 

·         Multiple commands can be entered on one line if you separate each with a semicolon.

      
          cd newdir ; ls -l  
 

·        Commands can continue beyond one line by using a backslash (\) character.

 


Special Characters

 
 NEWLINE   - initiates command execution 
 ;         - separates commands on same line 
 ( )       - groups commands or identifies a function 
 &         - executes a command in the background 
 |         - pipe 
 >         - redirects standard output 
 >>        - appends standard output 
 <         - redirects standard input 
 *         - wildcard for any number of characters in a
             file name 
 ?         - wildcard for a single character in a file 
             name 
 \         - quotes the following character 
 '         - quotes a string preventing all substitutions 
 "         - quotes a string allowing variable and 
             command substitution 
 `         - performs command substitution 
 [ ]       - denotes a character class in a file name 
 $         - references a variable 
 { }       - command grouping within a function 
 .         - executes a command (if at beginning of line) 
 #         - begins a comment 
 :         - null command 
     
 
 

·         Examples

1.   Use the * character in file names to match any number of characters. The following command:

               
                   ls  *.txt 
 

2.   Use the ? character in file names to match any single character. The following command:

              
                  ls  ???.txt 

3.   Use the [ ] characters in file names to match any character within a range of characters. The following command:

     ls  chapter[1-3].txt 

Terminal Control Keys

·         Several key combinations on your keyboard usually have a special effect on the terminal.

·         The most common control keys are listed below:

 
       CTRL-u   - erase everything you've typed on   
                The command line 
 
     CTRL-c   - stop/kill a command 
 
     CTRL-h   - backspace (usually) 
 
     CTRL-z   - suspend a command 
 
     CTRL-s   - stop the screen from scrolling 
 
     CTRL-q   - continue scrolling 
 
     CTRL-d   - exit from an interactive program 
 

 

Changing Your Password

·         To change your password: enter the command passwd and then respond to the prompts by entering your old password followed by your new one. You are then asked to retype your password for confirmation.

 

Getting Information

·         The "man" command

o        The "man" command man gives you access to an on-line manual which potentially contains a complete description of every command available on the system.

o        man can also provide you with one line descriptions of commands which match a specified keyword

o        The online manual is divided into sections:

o                      
o                          Section  Description
o                          -------  -----------
o                             1     User Commands
o                             2     System Commands
o                             3     Subroutines
o                             4     Devices
o                             5     File Formats
o                             6     Games
o                             7     Miscellaneous
o                             8     System Administration
o                             l     Local Commands
o                             n     New Commands
     

o        Examples of using the man command:

1.   To display the manual page for the cp (copy files) command:

     man cp

--More--23% at the bottom left of the screen means that only 23% of the man page is displayed. Press the space bar to display more of it or type q to quit.

2.   By default, the man page in section 1 is displayed if multiple sections exist. You can access a different section by specifying the section. For example:

     man 8 telnet 

3.   Keyword searching: use the -k option followed by the keyword. Two examples appear below.

 
     man -k mail 
     man -k 'copy files' 
               

4.   To view a one line description of what a command does:

     whatis more

 

·         who - shows who is on the system

 
            who
         who am i
     

·         finger - displays information about users, by name or login name or userid

 
       finger doe 
     finger userid 
 
·        cal – displays the calendar for a specified year, or month of year
               cal 04 2000
     

Logging Off The System

·         To finish using a UNIX system you must go through a process known as "logging out" or "logging off".

·         To logout enter the command logout or exit. If this does not, work press Ctrl-d.

·         If you have a .logout file in your home directory, the system will execute any commands contained there.

 

 

back to index