Quick viewing(Text Mode)

Course Goals

Course Goals

Lecture Notes 9-1-09 & 9-3-09 ENGR 0011 - Dr. Lund

• Welcome to ENGR 0011 • ENGR 0011 webpage • My webpage • Accessing my.pitt.edu • Intro to

Course Information • Professor : Laura Lund, PhD • Email : [email protected] • ENGR 11 Website : www.engr.pitt.edu/~eng11 • Text : Introduction to Engineering Analysis by Dan Budny • My website : www.pitt.edu/~lwlund courseweb.pitt.edu • TA : Michael Richard ([email protected])

Course Goals

• To develop programming skills

• To understand and learn to apply commonly used engineering analysis techniques

• To develop your writing, communication and team skills

• To significantly increase your expectation of and ability to manage a heavy homework load

1 Lecture Notes Chapter 2 - UNIX Topics… 1. Unix Commands Language for using Unix

2. Protocol for communicating with Unix

3. FTP protocol with Unix file system

4. PICO Unix text editor

5. Pine Unix email program

Why Are We Learning About UNIX?

1. So you can understand how to store, organize, access and manipulate webpages and other files on your personal Pitt Unix account space.

2. To teach the concept of absolute and relative addressing WHY?

This concept is important in programming because it is the means by which a programmer successfully and effectively accesses file data or runs other programs that are stored in locations different than the location of the program from where this information is being accessed. For example, you may want to create and store a program in a certain folder of your computer, but in that program you may need to read in data or run another sub-program that is stored in another folder on your computer, or maybe on another computer all together. How do you tell your program to find that data or sub-program?

1.A. Introduction to UNIX

• What is UNIX?

– UNIX is an designed for use on mainframe computers

– UNIX is a time-sharing and multitasking operating system

– Univ of Pittsburgh’s mainframe uses the UNIX operating system

– The Pitt UNIX mainframe stores all student, faculty and staff account information and files

– This mainframe is also a web ; everyone with an account on the Pitt mainframe can use their account to store and serve web pages

– UNIX software includes tools for communication between the mainframe and any network linked PC

2 1.B. UNIX Components

• Kernel – Master control; the part of the program which controls all computer operations

• Shell – user interface window; allows a user to send commands and receive information to and from the Kernel

• File System – system for storing units of information, or files; UNIX sorts files by user

• Utilities – useful programs which are part of the UNIX operating system, such as email programs, file editors, database programs…

1.C. Intro to the UNIX File System

• The value of learning to use the UNIX file system is that: – You can access the files you place here from any computer at Pitt and almost any computer worldwide (that is hooked up to a network) – You can create and post a personal web page • To communicate with the UNIX system and to access your UNIX account/folder requires a software program that utilizes a specific protocol. This type of communication program is referred to as a SHELL. • Telnet is a terminal emulation protocol (a shell) for communication between a local and remote computer in plain text. It is not a secure protocol! • SSH is a for communication which encrypts all keystrokes (i.e. your login and !)

1.D. Opening a secure session

• Pitt now requires the we use an SSH connection.

• To do so, we will be using a software program called “PuTTY ”. This program is available on many PCs, in our labs, and is free to download.

– Open the “PuTTY” program and make sure the “SSH” button is selected. – Enter the following in the Host Name (or IP address) box: unixs.cis.pitt.edu – Click “open ”. – Enter your university login and password. – After some system messages, you should see the UNIX prompt.

3 1.E. UNIX File System

• If you type the command “ pwd ” (stands for present working directory) and hit enter, you will be shown your home directory

• The top of the tree is known as the root directory, which is / (not /afs )

• All user account files are stored under the “home” subdirectory /afs/pitt.edu/home

1.F. Common Commands

• man – help command • pwd – present working directory • ls – list command • mkdir – make a new directory command • rmdir – remove directory command • cd – change directory command • rm – the remove command • cp – the copy command • mv – the move file command • chmod – changes protections on files and directorries • exit – logout of system

1.G.i. ls Command options

• -a lists all files, including .___ hidden files • -F indicates file types • -m shows files as a comma separated list • -s shows size of files • -C forces multiple column output • -1 forces single column output • -d forces ls to list directories rather than their contents • -R causes ls to list recursively directories below specified one • -l forces long listing, i.e. gives all file info

• Examples :

ls –a –l (lists all files in working directory with all file info)

ls public/html (lists files in subdirectory /afs/pitt.edu/home/l/w/lwund/public/html directory using relative addressing)

4 1.G.ii. “cp” Command

• Use to copy one or more files to a different directory, or to same directory with a different name • Examples:

– cp file1 file2 (Copies to same directory with different name)

– cp public/file1 private (copies to new directory, name stays same)

– cp file1 file2 file3 private/backup (Copies 3 files to private/backup directory, keeping same names)

– cp public/html/* private/backup (Copies all files in public/html to private/backup)

1.G.iii. “mv” Command • Use to move files or directories • Use to rename a file or directory • Examples: – Move a file… mv file1 private/file1.bkp (Moves file1 to private dirctory and changes name to file1.bkp) mv file1 private (Moves file1 to private, keeping same name) mv file1 file2 file3 private (Moves 3 files to private) – Move a directory… mv public/html/eng11 private/eng12bkp (takes eng12 directory and moves it and all of its files to a new directory under private called eng12bkp) – Rename a file… mv private/file1 private/file1.old

1.H. Absolute & Relative Addressing

• Path – the path is the direction to a subdirectory or file Ex: /afs/pitt.edu/home/l/w/lwlund/Public/html/ • Absolute addressing – the path starting from the root directory • Relative addressing – the path relative to the present directory – “..” Means up one level Ex: cd ../../../b/u/budny This command would follow the path of going up three directories from your home directory then down to the b/u/budny directory – For a relative path to a folder below (or within) your present directory, start with the name of a lower folder without putting a slash at the beginning Ex: cd public/html/

5 1.I. Special Addressing Characters

Wild Characters : * Can be used to represent multiple wild card characters (Ex: cp private/pictures/*.jpg ../../../b/u/budny/public )

? Can be used to represent a single wild card character

Absolute Addressing Characters: ~ Starts path at user’s home directory (Ex: cd ~/public/html) . Refers to present working directory (Ex: mv /private/Courses/file1 . )

Sample Unix File System

User’s home /afs/pitt.edu/home/j/o/joeng

public private backup

html R10 eng11 calc chem

homework classwork

hw1 hw2 hw3 hw4 ca090406

Some Examples

Assume you are “ joeng ” and have opened a Telnet session with your Unix account, and are currently in your home directory. Your file system is shown on the screen above.

• If you type “pwd”, what would be returned? /afs/pitt.edu/home/j/o/joeng • Using relative addressing, what command would you use to list the contents of the “homework” directory? ls private/eng11/homework • Using absolute addressing, what command would you use to change your current location to the “R10” directory? cd /afs/pitt.edu/home/j/o/joeng/public/R1

6 • Now that you are in the R10 directory, what single command would you use to copy all of the homework files from the homework directory to the R10 directory (use relative addressing)? cp ../../private/eng11/homework/hw* . • What command would you use to create a new directory called “writing” under the “eng11” directory, from the R10 directory? mkdir ../../private/eng11/writing • What command would you use to list the contents of the R10 directory so that you can view all of the files with their protection modes? ls –a –l or ls -al • What command would you use to get help on the “ls” command if you forgot the extensions? man ls

1.J. More Commands

• finger – finger command for finding people • cat [filename] – (catenate) displays contents of file • cal – calendar • date – gives day, date and time • more [filename] – affects how info is displayed • pg [filename] – similar to more • grep – search command • who – gives a list of the users currently signed on to UNIX • who am I • clear – clears screen • du –k – gives disk utilization • tree –d – shows file folder structure of account

1.K. File names in UNIX

• Very flexible up to 256 characters (128 on some older systems) • Any type of characters – numbers, letters, dash, comma, etc. • NEVER USE SPACES IN A UNIX FILE NAME • stuff, STUFF, Stuff, stuFF are all different!

7 3.A. What is “sftp”?

• “sftp” is a secure used to transfer files between a local system (your computer) and a remote system (Pitt’s server). • You will need to be able to do this if you wish to store files in your account on Pitt’s server, which you must do to create your web page. • Two ways to run the “sftp” protocol:

– Using WinSCP (a Windows based program - easier) – Using an “sftp” command within a session (messier)

3.B.i. WinSCP • WinSCP is an open source SFTP for Windows. Its main function is the secure file transfer between a local and a remote computer. • http://winscp.net/eng/download.php

3.B.ii. WinSTP

8 3.C. UNIX sftp • To run an ftp program without WinSCP, we no longer use “ ftp ” at the command prompt in UNIX communication shell. We need to use “ sftp ”. • To ensure a secure sftp, use PuTTY’s SFTP tool. – Find it in the Start Menu under PuTTY. – Type open unixs.cis.pitt.edu – Enter user name and password. – You can use traditional ftp commands shown on the next page to view directories, and manipulate files or directories. – Not the recommended way to accomplish file transfer tasks – use WinSCP.

3.C.i. What Unix ftp commands do I need to know?

• help - gives a listing of commands • dir - prints a listing of remote directory • !dir - prints a listing of local directory (use ! Before any command to make it apply to local directory) • ls - prints an abbreviated listing of remote directory • cd - change remote directory

• get - use to retrieve a file (ex. get private/file1) • put - use to send a file (ex. Send c:/user/file1 private/file1) • send - same as put • mget - use to retrieve more than one file • mput - use to send more than one file

• bye - terminates connection and exits ftp

4. How do I create a file in UNIX? • You can create an ASCII text file using a program such as Notepad or Word, then transfer it to your UNIX account using WinSCP, OR… • You can create a file in UNIX using one of 2 text editor programs: – PICO – vi • We will use PICO , which is disscussed in greater detail in the textbook

9 4.A. PICO • To edit or create a text file in UNIX using PICO, type “ pico filename ” at the command prompt

• Once the file is open, you can simply type text in text window.

• Commands are listed at the bottom of the window and are executed by holding down the control key

4.A.i. PICO Commands

• To open a file: Read file ^R • To save a file: Write out ^O • To select text: ctrl-shift-6 (^^) • To cut text: Cut text ^K • To paste text: UnCut ^U • To spell-check: To Spell ^T • Help: Get help ^G • To exit: ^X

4.B. Notepad

• Notepad is a Windows based text Editor

• WordPad is also a text editor

• When saving a text file using WordPad, a .txt extension will be automatically appended to the file. This must be manually removed if necessary

10 5. Web Pages of Interest

• www.technology.pitt.edu – Documentation link – Software and Hardware link • www.bsd.org/unixcmds.html – Summary of Unix commands • www.ee.surrey.ac.uk/Teaching/Unix/ – Unix tutorial for beginners

11