CS2042 - Unix Tools - Fall 2010 - Cornell University

29
CS2042 - Unix Tools Fall 2010 Hussam Abu-Libdeh based on slides by David Slater September 8, 2010 Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Transcript of CS2042 - Unix Tools - Fall 2010 - Cornell University

Page 1: CS2042 - Unix Tools - Fall 2010 - Cornell University

CS2042 - Unix ToolsFall 2010

Hussam Abu-Libdehbased on slides by David Slater

September 8, 2010

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 2: CS2042 - Unix Tools - Fall 2010 - Cornell University

Course Information

When: September 8th - October 4rd; 3 times a week

Where: MWF 12:20 - 1:10 in Phillips 203

Drop Deadline: September 15th, one week into the course

Passing grade for completing all assignments successfully

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 3: CS2042 - Unix Tools - Fall 2010 - Cornell University

Course Information

Office Hours: ??

Email: hussam at cs.cornell.edu

Website: http://www.cs.cornell.edu/courses/cs2042/Still waiting on server permission

CMS: http://cms.csuglab.cornell.edu

If you preregistered you should be on CMS

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 4: CS2042 - Unix Tools - Fall 2010 - Cornell University

Course Goals

Overall Goal: Gain an understanding of the Unix environmentand simple shell scripts

More specifically

FilesSecurityText ProcessingRegular ExpressionsThe Shell EnvironmentA variety of Shell commandsBasic Shell Scripting

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 5: CS2042 - Unix Tools - Fall 2010 - Cornell University

Prerequisites

Not assuming any previous experience with the UNIXenvironment

Basic understanding of programming helpful

(but probably not even necessary)

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 6: CS2042 - Unix Tools - Fall 2010 - Cornell University

What Is Unix?

One of the first widely-used operating systems

Basis for many modern OSes

Helped set the standard for multi-tasking, multi-user systems

Strictly a teaching tool (in its original form)

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 7: CS2042 - Unix Tools - Fall 2010 - Cornell University

Short history of UNIX

’60s The ambitious project MULTICS (Multiplexed Informationand Computing System) fails, but a number of seminal ideas(like pipes and shells) are proposed

’69 Ken Thompson, Dennis Ritchie (et al.) start working on a filesystem, and name their system UNICS, which is later changedto UNIX.

UNIX was “small, simple and clean”, and distributed freely tomany universities, where it becomes popular

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 8: CS2042 - Unix Tools - Fall 2010 - Cornell University

Short history of UNIX

’73 Thompson and Ritchie rewrote UNIX in C (while most of theoperating systems at that time were written in assembly)

’81 Berkley UNIX 4.1 BSD: vi, C shell, virtual memory

’91 Linux, GNU, and others: similar to UNIX, but their sourcecode rewritten, very popular and widespread, free

Currently, X/Open is responsible for developing UNIXMany Linux Distributions: Ubuntu, Fedora, Debian, ...

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 9: CS2042 - Unix Tools - Fall 2010 - Cornell University

Current UNIX Flavors

Berkeley Software Distribution (BSD)

Suns Solaris

GNU/Linux

Apple OSX

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 10: CS2042 - Unix Tools - Fall 2010 - Cornell University

Berkeley Software Distribution

Developed by students and faculty at UC Berkeley

Forked from the proprietary version back in the 80s

Has since split into many additional flavors - namely,

NetBSD, OpenBSD, and FreeBSD

Spawned a popular open-source software license (the BSDLicense!)

Primary competitor to Linux among free OSes

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 11: CS2042 - Unix Tools - Fall 2010 - Cornell University

Solaris

Commercial offshoot of BSD

Designed to run on Suns SPARC servers, since ported to x86

Most of the source code was recently released for theOpenSolaris project

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 12: CS2042 - Unix Tools - Fall 2010 - Cornell University

Linux!

Pieced together by a Finnish guy named Linus Torvalds

starting in 1991

Built over the internet using message boards (Usenet)

Designed to a UNIX-like standard, but not a direct descendant

Note:

Linux technically only refers to the OSs core, or kernel - withoutother programs it cant really do anything.

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 13: CS2042 - Unix Tools - Fall 2010 - Cornell University

GNU

GNU = Gnu is Not Unix

Movement in the 80s to build a free OS

Created many very popular tools

Unix like but uses no Unix code

Stallman says:

There really is a Linux, and these people areusing it, but it is just a part of the system theyuse. Linux is the kernel: the program in thesystem that allocates the machines resourcesto the other programs that you run. Linux isnormally used in combination with the GNUoperating system: the whole system is basicallyGNU with Linux added, or GNU/Linux.

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 14: CS2042 - Unix Tools - Fall 2010 - Cornell University

GNU/Linux

Like BSD, GNU/Linux has a variety of flavors called“distributions”. These versions generally have different designgoals (security, speed, desktop use) and package a unique set oftools with the kernel to achieve them.

Hundreds of distributions

Popular distributions include RedHat, Ubuntu, SuSE,Slackware, Gentoo

Saying “GNU/Linux” every time is tedious, so we will just refer tothe entire system as “Linux”.

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 15: CS2042 - Unix Tools - Fall 2010 - Cornell University

Apple OSX

built using a BSD-based kernel which was renamed “Darwin”

Arguably the most popular desktop version of UNIX

A pretty, easy to use experience built on a powerful frame

Steve Jobs Says:

What can the fully compliant UNIX technology inLeopard do? It can run any POSIX-compliant sourcecode. Help you make the most of multicore systems.Put a new tabbed-interface Terminal at yourfingertips. Introduce a whole host of new featuresthat make life easier for every developer. Really, whatcant it do?

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 16: CS2042 - Unix Tools - Fall 2010 - Cornell University

Advantages/Disadvantages: BSD

Pros

Reliable and very secure

Usable on almost anything that uses electricity

Most flexible license

Free!

Cons

Least community/professional support

Many flavors to choose from

You thought Linux was for nerdy outsiders?!

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 17: CS2042 - Unix Tools - Fall 2010 - Cornell University

Advantages/Disadvantages: Solaris

Pros

Built specifically for the hardware it runs on

Scales really well as system size/load increases

Lots of support from Sun as well as the community

Cons

You are paying for Sun’s support and probablythe hardware

Primarily for server use, not superdesktop-friendly

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 18: CS2042 - Unix Tools - Fall 2010 - Cornell University

Advantages/Disadvantages: Linux

Pros

Huge community support base

Free (unless you want professional support)

Free software to do almost anything

“wine” allows you to run almost any windows program

(even WoW if you are into that sort of thing)

Cons

Dizzying array of distribution choices

Lacks some widely-used software (Office,Photoshop etc)

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 19: CS2042 - Unix Tools - Fall 2010 - Cornell University

Advantages/Disadvantages: OSX

Pros

User friendly and just works

Fully-featured GUI with a powerful terminal

Supports most of the software the others lack

Cons

Definitely paying for this one!

Closed-source, not as flexible as Linux

Only runs on hardware purchased from Apple(without breaching the EULA)

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 20: CS2042 - Unix Tools - Fall 2010 - Cornell University

RoadMap

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 21: CS2042 - Unix Tools - Fall 2010 - Cornell University

Why Linux?

IT’S FREE

More widely used than BSD or Solaris

Easy to find beginner’s guides online if you need them

Basic tools are pretty much standardized

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 22: CS2042 - Unix Tools - Fall 2010 - Cornell University

What is the course about?

Powerful text based program launcher. We will learn how to stringtogether simple programs to perform powerful tasks

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 23: CS2042 - Unix Tools - Fall 2010 - Cornell University

Unix shells

A shell is a program that allows the user to interact with the UNIXsystem:

read user’s input and parses it

evaluates special characters

setup pipes, redirections, and background processing

find and setup programs for execution

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 24: CS2042 - Unix Tools - Fall 2010 - Cornell University

For Example...

Help, all my images are named wrong!

2007-09-24-picturename.jpg

should be

24-09-2007-picturename.jpg

for fn in *.jpg

do mv $fn ‘echo $fn |\

sed ‘s/([0-9]+)-([0-9]+)-([0-9]+)/\3-\2-\1/’‘

done

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 25: CS2042 - Unix Tools - Fall 2010 - Cornell University

For Example...

What commands do I use most?

history | awk ’{print $2}’ | sort | uniq -c | sort -nr |head

229 screen

146 exit

136 ls

81 vi

64 w

47 math

43 cp

33 cd

25 who

23 history

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 26: CS2042 - Unix Tools - Fall 2010 - Cornell University

Unix Shells

There are primarily two “families” of unix shells:

Bourne shell (AT&T) sh ⇒ ksh ⇒ bash

C shell (Berkley) csh ⇒ tcsh

We focus on bash: easy syntax and default in many systems

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 27: CS2042 - Unix Tools - Fall 2010 - Cornell University

Getting to a UNIX Shell

If you are registered for the course, you have an account with theCS undergrad lab. To access it go to

http://www.csuglab.cornell.edu/userinfo/

You can ssh into the machines in the lab. Instructions are availableat the csuglab webpage. For windows machines,can use Putty(free) or Secure Shell (not free) to connect. If you are using anyother system you should have the simple tool ssh:

Example Login:

ssh [email protected]

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 28: CS2042 - Unix Tools - Fall 2010 - Cornell University

Installing Linux on your machine

Most modern Linux distros (distributions) are easy to install.

Disk repartitioning and dual boot automatically set up for you(so you can have Windows and Linux side by side)

To install Linux:1 Download a Linux iso file (CD image file)

www.opensuse.orgwww.ubuntu.comwww.fedoraproject.org

2 Burn the iso image into a CD3 Boot your computer from the CD and follow the simple install

wizard4 Enjoy! :-)

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools

Page 29: CS2042 - Unix Tools - Fall 2010 - Cornell University

Other Options

If you have a windows machine, there are a few other options:

cygwin: a Linux-like environment for Windows(http://www.cygwin.com/)

wubi: Ubuntu Linux installer for windows. Can dual bootwindows and ubuntu without repartitioning(http://wubi-installer.org/)

any linux live cd (http://www.livecdlist.com)

Linux on a flash drive!

VMWare: run any Unix environment within windows

None of the assignments “should” require you to be logged intothe csug machines.

Hussam Abu-Libdeh based on slides by David Slater CS2042 - Unix Tools