COMP 104: Intro to Unix Week 1. Agenda Welcome to Comp 104! Roster and Introductions Class Web Site

Preview:

Citation preview

COMP 104: Intro to Unix

Week 1

Agenda

Welcome to Comp 104! Roster and Introductions Class Web Site

https://online.franklin.edu/CourseLogin?section=comp104-23ff

Personal Web Site https://cs.franklin.edu/~morrisok/comp104/

Agenda – Activity 1

Introduction to UNIX What is an operating system? Brief history of the Unix Operating

System The design philosophy of Unix

Agenda - Activity 2

How to use the UNIX system Korn shell Command Line interface Demonstration of login procedure

How to use PuTTY to log into the class Unix server einstein.

Changing your global password on email.franklin.edu

(login, passwd, changepasswd, exit) Practice login procedure (Individual) Practice changing password (Individual) The shell and environment variables

(echo, set, export, setenv) Break (10 minutes)

Agenda – Activity 3

UNIX Online Manual What is it? How can it help?

(man, whatis) Demonstration of Online Manual

UNIX Commands Working with files:

(ls, cat, more, wc, lp) Demonstration of working with files

commands. Break (10 minutes)

Agenda - Activity 3 Continued

More UNIX Commands Getting System Information:

(date, finger, whoami, whereis, who, hostname, uname)

Demonstration of system information commands.

In Class Assignment #2 Other Interesting Commands:

(echo, exit, set, setenv, alias, talk) Demonstration of other interesting commands. In Class Assignment #3

Preview of next week In class assignment

Professor Information

D Kris Morrison Work Number : 435-1303 Home Number: 833-4725 Email: morrisok@frankin.edu

I can not check email during the day. I will check email every evening and multiple times on the weekends.

Course Assignments

The subject line for your assignments and papers must be:

Comp104LastNameAssignmentNumber

For example: Comp104Morrison1-1

Course Assignments

If you email a question, please put the word “Question” in the subject line.

Activity 1

Operating Systems

What is an Operating System? A master control program It controls the execution of application

programs Acts as a primary interface between

user and hardware

Operating Systems

What functions does an operating system do?

Controls memory usage Maintains file storage system Schedules work Provides accounting Provides security

Operating Systems

Three types of Operating Systems Single-user, single-process

DOS Single-user, multiple-process

OS/2, Windows NT, Windows XP Multi-user, multi-process

Unix, Linux, VM, MVS

Operating Systems

What objectives should we consider when designing an Operating System?

Convenience Functionality Efficiency Ability to evolve

History of Unix

Unix was developed in 1969 by Ken Thompson of Bell Labs (now AT&T).

http://www.bell-labs.com/history/unix/

http://www.levenez.com/unix/

From Multics to Unix

Multics (Multiplexed Information and Computing Service) was a collaboration between Bell Labs, GE, and MIT. It was a time-sharing operating system that supported multiple users. (~ 1965 - 1969)

Ken Thompson, who worked on Multics, created his own operating system. It was a single-user operating system, so he called it Unics (Uniplexed Information and Computing Service)

Unics eventually became Unix

Design Philosophy of Unix

Unix has three important characteristics:

It is Multi-Tasking It is Multi-User It is Portable

Unix is also considered to be an ‘Open’ system. It can be customized to meet your needs.

Design Philosophy of Unix

Designed by smart people for smart people

Does not suffer fools gladly

The Many ‘Flavors’ of Unix

There are many versions of Unix, including: AIX (IBM) HP-UX (Hewlett Packard) Solaris (Sun Microsystems) Ultrix (Digital Equipment Corporation) Unixware (Novell) Linux (Linus Torvalds) NetBSD FreeBSD

At Franklin, we will use Sun Solaris for Unix training.

The Unix Connection

There are several types of computers in a Unix network:

Host Computers This is the main computer that performs the work

The Unix Connection

Terminal Computers These are the computers that you use to

connect to the Host. They consist of a monitor and a keyboard.

There are two types of terminals: Graphical User Interface (GUI/X-Windows) Character User Interface (CUI)

The Unix Connection

Terminal

HostTerminal

Terminal

Our Technical Environment

Terminal

Terminal

Server

Terminal

Terminal

einstein

Activity 2

The Unix Shell

Unix runs a “Shell” that allows you to execute commands. You can think of this as a Command Processor (program).

The most commonly used shells are: Bourne Korn C

The Korn Shell

This shell was created by David Korn, a scientist at Bell Labs.

The name of the Korn shell program is ksh.

Korn Shell Concepts

Shell Variables

* The shell uses Variables to maintain and pass information between programs

Examples: TERM, PATH, SHELL, PRINTER, PAGER, PS1

To display the value of a variable: echo $TERM

Extra: Users can define their own variablesMYVAR=“Unix is cool”print $MYVAR

Korn Shell Concepts

The Initialization file (.profile)

• The commands in this file are executed each time you login. Located in your home directory.

• Shell variables PATH, TERM, PS1, and PRINTER are initialized in your local .profile

• Umask and some aliases are also set in your local .profile

• Use “vi” editor to change, or customize your .profile

Korn Shell Concepts

The PATH shell variable

* The variable tells the shell where to look for programs.

Example:

PATH=.:/export/home/morris07/bin:/usr/local/bin:/bin:/usr/bin

Command Line Interface

You will work from a Command Line to type in commands. The entire line you type in is the Command Line. Separate multiple commands using semicolons.

/export/home/morris07/>________________

You type in commands and then type <enter>

General format of command: command-name options parameters

NOTE: Unix is CaSe sEnSiTiVe!!

The History File

The Shell saves all commands entered in a list called the HISTORY FILE. This history file is located in your home

directory. (.sh_history) Each command gets an ID# starting at 1. To display the history list use the history

command. To re-use a command in the history file, you

can use the r command: r, r 24, r da, r w Built-in-editors let you recall, edit, and re-

execute commands from the history file or the current command you are currently typing. Use “vi” commands to edit commands. <Esc>, <Enter>

Logging Into Unix

PuTTY is freeware that provides secure access from a PC

Required for secure access into the class Unix server einstein from our classroom.

Required for secure access from a remote location, such as your home or your office

Download PuTTY and view directions at the CLAS Lab Reference Manual web page: http://www.franklin.edu/programs/comp/resources/claslab/index_html/view

Logging Into Unix

Locate the PuTTY icon on your desktop and double click to open.

Logging Into Unixeinstein.franklin.edu

cs.franklin.edu

192.70.252.8

Select SSH

Highlight

cs and

Select

Load

Select

Open

Logging Into Unix

Login Demonstration

Practice Logging Into UNIX

Unix Commands: login

Use login to log on to the system

login:

Actually, this is the UNIX program that is run so you can login to the einstein UNIX server.

Unix Commands: passwd

The standard Unix command passwd or changepasswd is not available to change your einstein password at Franklin University. Use web page: https://email.franklin.edu/ to change your password globally.

For other Unix systems, use passwd to change your login password and password attributes.

Changing your password

Changing your password

Practice Changing Your Password

Unix Command Syntax

The format of all Unix commands is Command {Options..} (Parameters..}

Commands can have only options. Commands can have only parametes. Commands can have both. Commands can have neither.

Unix Command Syntax

Options Follow directly after the command Indicated by a minus sign (-) Multiple options can be specified in

any order Control how the command executes

Unix Command Syntax

Parameters Parameters pass information to the

command. The most common parameter is file

name. Tell the command what to operate on.

The Unix Shell: exit

Use exit to end the execution of the current shell. Will log out from Unix.

/export/home/morris07/> exit

Note: You can also use logout to log out from Unix

The Unix Shell: <cntl> C

To halt the execution of a command, use ^c (read ‘control c’).

Note: Whenever you see ‘^’ in Unix, it means ‘hold the <ctrl> key’.

The Unix Shell: print (echo)

Use print to echo arguments to the command line/export/home/morris07/> print “hello”

Use the $ symbol for Environment Variables/export/home/morris07/> print $TERM/export/home/morris07/> print $SHELL

The Unix Shell: echo (print)

The “echo” command works exactly the same way as “print”.

Dr. Korn intended “print” to be used.

“Print” is implemented the same way on all Unix systems. “Echo” may have some differences.

Demonstration of echo

The Unix Shell: set

Use set to display and set Shell Variables and Options on your system

/export/home/morris07/> set (Displays Variables)

To set Variables:/export/home/morris07/> export {VARIABLE}={VALUE}

/export/home/morris07/> set –o(Displays Options)

The Unix Shell: setenv

Use setenv to display Shell Variables (only if you use the C Shell)

/export/home/morris07/> setenv

NOTE: Since we are not using the C Shell, this will not work for us

Demonstration of set

Question/Answer Session

Break (10 Minutes)

Activity 3

The Online Manual

The ONLINE MANUAL is a collection of files that contain documentation about Unix commands or topics.

This is accessible through the man command

Unix Commands: man

Use man to find and display reference manual pages

/export/home/morris07/> man command/export/home/morris07/> man –k {keyword}

/export/home/morris07/> apropos {keyword}

Demonstration of man

Demonstration of man -k

Unix Commands: whatis

Use whatis to display a one-line summary about a keyword

/export/home/morris07/> whatis {keyword}

NOTE: This is the same as the man –f command

Demonstration of whatis

Working With Files: ls

Use ls to list the contents of a directory

/export/home/morris07/> ls (list in column format)/export/home/morris07/> ls –a (lists all entries*)

* This will also list System or ‘Hidden’ files ( ‘.’ files)/export/home/morris07/> ls –l (long listing)

/export/home/morris07/> ls –la (long and all files)

/export/home/morris07/> ls –F Mark directories with a trailing slash (/), and executables with a trailing (*).

Demonstration of ls

Demonstration of ls

Working With Files: cat

Use cat to display and concatenate files (third week)

/export/home/morris07/> cat {filename}

/export/home/morris07/> cat {file1} {file2} > {file3}

Demonstration of cat

Working With Files: head,tail

The commands head and tail also display files.

head {-count} {filename} tail {-count} {filename}

Working With Files: head,tail

Working With Files: more

Use more to browse a text file one page at a time

/export/home/morris07/> more {file name}

NOTES: Type <return> to go forward one space Type <space> to go forward one page Type q to end

Extra: less is another popular pager. (Found in /opt/Util)

pg is also used often as a default pager.

Working With Files: more

Working With Files: wc

Use wc to display a count of lines, words, and characters in a file

/export/home/morris07/> wc {file name}

/export/home/morris07/> wc –c (a count of characters)/export/home/morris07/> wc –l (a count of lines)/export/home/morris07/> wc –w (a count of words)

Working With Files: wc

Working With Files: lp

Use lp to submit print requests

/export/home/morris07/> lp

/export/home/morris07/> lp –d NE {file name}

Question/Answer Session

Break (10 Minutes)

Getting System Info: date

Use date to display the date and time

/export/home/morris07/> date

NOTE: If you have the root access, you can also use this to set the time and date

Getting System Info: date

Getting System Info: finger

Use finger to display information about local and remote users

/export/home/morris07/> finger

/export/home/morris07/> finger -m {username}

Create .plan file in home directoryIf you have a .project file, finger will display the first lineMake sure permissions are set to 755Students must use finger –m Some versions of finger also display info about mail.

Getting System Info: finger

Getting System Info: who

Use who to display who is logged onto the system

/export/home/morris07/> who

This lists the user name, terminal name, login time, elapsed time, and the process ID.

Getting System Info: who

Getting System Info: whoami

Use whoami to display your username

/export/home/morris07/> whoami

/export/home/morris07/> who am i

Getting System Info: whoami

Getting System Info: whereis

Use whereis to locate the binary, source,and manual page files for a command

/export/home/morris07/> whereis {command}

Getting System Info: whereis

Getting System Info: hostname

Use hostname to display or set the name of the current host system

/export/home/morris07/> hostname

Note: Must be super-user to be able to set the host name. I.e system administrator.

Getting System Info: hostname

Getting System Info: uname

Use uname to print the name of the current system

/export/home/morris07/> uname(Current Operating System Name)

/export/home/morris07/> uname –r(Prints Operating System Release Level)

/export/home/morris07/> uname –a(Prints basic information)

Getting System Info: uname

Question/Answer Session

The Unix Shell: alias, unalias

Use alias to create a pseudonym or shorthand for a command or series of commands. Use unalias to remove the alias.

/export/home/morris07/> alias {name}={command}

/export/home/morris07/> alias

/export/home/morris07/> unalias {name}

The Unix Shell: alias, unalias

The Unix Shell: alias, unalias

Using the talk command

Use talk like instant messenger Both parties are presented with talk windows mesg [y] [n] command controls whether or

not others can send messages to your terminal screen. mesg with no argument causes current permissions to be displayed.

Talk has been disabled Extra: Use the write user command to

communicate with another logged-in user. write morris07

Question/Answer Session

Wrap Up: What We Covered

Brief history of the Unix Operating System

The design philosophy of Unix Use of the Korn shell and the

Command Line interface The shell and environment

variables

Wrap Up: What We Covered

How to use PuTTY to log into the class Unix server einstein.

Changing your global password on email.franklin.edu.

Used the following Unix commands:alias, cat, date, echo, exit, finger, hostname, login, lp, ls, man, more, passwd, set, setenv, uname, wc, whatis, whereis, who, whoami

Question/Answer Session

Assignments for Next Week

1-2 page Paper www.turnitin.com Class ID = 1115883 Class password Comp104S5

Worksheet from website Due next Tuesday If you send it to me, I’ll send you back

the answers.

Help for turnitin.com

A help sheet is available at

http://cs.franklin.edu/~varnerp/TurnItInHowTo.doc.

APA Guidelines

Information is available at: http://www.franklin.edu/students/library/citeanddoc.html

APA Guidelines

"APA style" is a set of specific citation formatting conventions sanctioned by the American Psychological Association.

APA Guidelines

Do not have sources in your reference or works cited page unless they are cited in the text of your paper.

Always provide a citation for anyone else's work you paraphrased or quoted.

Always provide a page number for any quotations you use.

APA Examples

Go to webpage.

Preview Of Next Week

Unix file system structure File types and access permissions Create and use directories and files Edit files with vi Use the following Unix commands:

cd, chmod, cp, id, mkdir, mv, pwd, rm, rmdir, touch, umask, vi

Question/Answer Session

Transferring files to einstein from your PC

WinSCP2 is software that provides secure FTP (File Transfer Protocol), which allows you to transfer files to and from a PC (freeware) Required for secure FTP to/from the class

Unix server einstein. Required for secure FTP from a remote

location, such as your home or your office Download WinSCP2 and view directions at the

CLAS Lab Reference Manual web page: http://www.franklin.edu/programs/comp/resources/claslab/index_html/view

Transferring files to einstein from your PC

Locate the WinSCP2 icon on your desktop and double click to open.

Transferring files to einstein from your PC

einstein.franklin.edu

cs.franklin.edu

192.70.252.8

User name for einstein

Password for einstein

Directory on einstein

Directory on your PC

Hit this button to start secure FTP session with the class Unix server einstein

Transferring files to einstein from your PC

Save and Load your sessionDefault

session name

Transferring files to einstein from your PC

Select file to copy

Hit copy button or F5

Select working filesystem

Unix File Editors

vi (pronounced “vee-eye”) is a visual editor that was created by Bill Joy.

vi is a “right-handed” editor

Other Unix editors: pico, emacs

The vi Editor

Use vi to edit files

> vi {file}

NOTE: If the file does not already exist, vi will create it for you.

The vi Editor: Modes

vi has two different modes:

Command ModeIn Command Mode, the characters you type are interpreted as commands.

Input ModeIn Input Mode, everything you type is inserted into the editing buffer.

The vi Editor: Modes

vi starts in Command Mode by default

Type <Esc> to change from Input Mode to Command Mode

Hint: If you forget which mode you are in, hit the <Esc> key twice to get to Command Mode.

Hint: :set showmode will display the input mode in the lower right hand corner of the screen.

The vi Editor: Inserting Data

From Command Mode:

i changes to Input Mode: insert before current position

a changes to Input Mode: insert after current position

I changes to Input Mode: insert at start of current line

The vi Editor: Inserting Data

From Command Mode:

A changes to Input Mode: insert at end of current line

o changes to Input Mode: open below current line

O changes to Input Mode: open above current line

The vi Editor: Saving and Exiting

In Command Mode (colon commands)::w writes data to the file (saves changes):wq writes data to the file and quits:w filename writes buffer to the named file:q quits:q! quits without savingZZ quits and saves

The vi Editor: Moving the Cursor

In Command Mode:

h, move cursor one position to the left

j , move cursor one position downk , move cursor one position upl , move cursor one position to the

right

The vi Editor: Deleting Data

x delete character at cursorX delete character to left of cursorD delete from cursor to end of linedw delete one worddd delete the entire current line

The vi Editor: Replacing Data

r replace a single character at the cursor

ra* Replaces the current character with “a”

R replace characters by typing over

Rnew stuff* Replaces the text at cursor with “new stuff”

cw replace the word by typing over

Class Practice

Open Notepad or any other text editor.

Enter 4 or 5 lines of data. Save and close the file. Use WinSCP3 to send the file to your

home dirctory: /export/home/<userID>

Open vi and edit the file Vi <filename>

Make a few changes. Save and close the file.

ZZ in command mode

Class Practice

Recommended