unix 101: unix for windows users

116
UNIX 101: UNIX For Windows Users Lecture 1 9 September 2005 Sponsored by ACM 1

Upload: kimball

Post on 14-Jan-2016

119 views

Category:

Documents


0 download

DESCRIPTION

UNIX 101: UNIX For Windows Users. Lecture 1 9 September 2005 Sponsored by ACM. 1. The Cold Hard Truth. This course is NOT officially sponsored by the CS department You will NOT receive credit for this course - neither will we for that matter - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: UNIX 101: UNIX For Windows Users

UNIX 101:UNIX For Windows

Users

Lecture 19 September 2005 Sponsored by ACM

1

Page 2: UNIX 101: UNIX For Windows Users

The Cold Hard Truth•This course is NOT officially sponsored by

the CS department

•You will NOT receive credit for this course - neither will we for that matter

•If we say something that offends you, deal with it.

•You should try NOT to snore when you fall asleep

•We did this course on our own time, so try to make the best of it for all of us.

2

Page 3: UNIX 101: UNIX For Windows Users

Just Who Do We Think We Are?

•Mark Kegel - Tall Guy with Black Hair

[email protected]

•Marshall Pierce - Broad Shouldered Guy

[email protected]

3

Page 4: UNIX 101: UNIX For Windows Users

And Just What Do We Think We’re

Doing?•We are here to teach you (what we

think are) the fundamentals of Unix.

•We are here to teach you to teach yourself about Unix.

•We’re on a mission from God.

4

Page 5: UNIX 101: UNIX For Windows Users

Never Mind Us, Who Are You

People?•Students who have no experience

with Unix

•Students who have some experience but want a better grounding in Unix

•Someone who is lost, confused, and looking for spiritual enlightenment

5

Page 6: UNIX 101: UNIX For Windows Users

Some Reasons to Learn About Unix•Growth of Linux

•OS X is based on Unix

•Expanded skill set - useful knowledge

•You want to be a l33t h4X0r

•BTW, you will always be teh newb

6

Page 7: UNIX 101: UNIX For Windows Users

Some Better Reasons to Learn

About Unix•I want to show my girl\boy-friend some cool Unix tricks

•FYI: Real CS Majors never see the light of day much less significant others

•I am a CS major...

•...or I plan on taking a class (CS60 or above) from the CS department

7

Page 8: UNIX 101: UNIX For Windows Users

The Best Reasons To Learn About

Unix...•As a CS major at Mudd you need to

have a working knowledge of Unix

•The CS department refuses to offer a Unix course (they do have good reasons though!)

•But why are you really here?

8

Page 9: UNIX 101: UNIX For Windows Users

To Make This Perfectly Clear...

•We will NOT teach you how to use application XXXX or show you neat tricks for application XXXX

•This course is not the equivalent of a course in Word or Excel

•We will also NOT teach you to how to program in Unix

9

Page 10: UNIX 101: UNIX For Windows Users

Down To Business...

•Computing Resources Available To You

•Terminal Room: Beckman B102

•Mac minis (aren’t they just so cute)

•Printer: gute.cs.hmc.edu

•Graphics Lab: Beckman B105

•some old’n’busted computers

10

Page 11: UNIX 101: UNIX For Windows Users

•AC and LAC Labs

•Windows and Mac Computers

•Printers: Odie and Cujo, Clifford and Astro

•Scanners in alternate AC lab

•Engineering Lab

•Houses engineers, avoid at all costs (they snarl and bite; Holy Water and Crosses are said to keep them away)

11

Page 12: UNIX 101: UNIX For Windows Users

All-Campus Servers•odin.ac.hmc.edu

•RHEL server; Student POP server

•thuban.ac.hmc.edu

•VMS server; hosts DNS

•banshee.st.hmc.edu

•Huge Cisco box; campus wide router

12

Page 13: UNIX 101: UNIX For Windows Users

•turing.cs.hmc.edu (sparc)

•primary work server - you’ll do most of your work from here

•knuth.cs.hmc.edu (x86)

•our new server - where you ought to be working when you can

•wilkes.cs.hmc.edu (x86)

•alternate work server

•muddcs, ark, cortana, durandal

CS Dept. Servers

13

Page 14: UNIX 101: UNIX For Windows Users

The Doctor Will See You Now

•Mudd employs several whose jobs entail fixing computer and network problems

•Tim Buchheim - Computer Science Dept.

•Maintains the CS Department computers

•Roger Wiechman - CIS

•Maintains the Mudd Network

14

Page 15: UNIX 101: UNIX For Windows Users

When Hippies walked the earth...•Computers were real dinosaurs

•Barely had timesharing systems

•No video terminals - teletypes instead

•RAM and CPU power limited

•there’s only so many beads you can fit on an abacus

15

Page 16: UNIX 101: UNIX For Windows Users

When Hippies walked the earth...

•Ken Thomson

•Invented UNICS in 1969

•UNIplexed Information and Computing Service

•That year also ARPANET, and man most likely landed on the moon

•Why? He needed a way to play a game...

•After that Unix's history is kind of a blur16

Page 17: UNIX 101: UNIX For Windows Users

Unix Today•Fundamentally multi-user and multi-tasking

•Programmer’s and tinkerer’s environment

•Support and encouragement for hacking the system; FOSS is your friend

•Powerful tool in the right hands

•Runs the world’s most powerful computers

•Is a thirty year old OS that Microsoft still hasn’t been able to copy correctly

17

Page 18: UNIX 101: UNIX For Windows Users

The Idea of Unix?

•Unix is more than an OS, it is

•a programming language - C

•a broad philosophy of how computers and users should interact

•an interface - POSIX

•more than the sum of its parts

•the code that Ken Thomson wrote?

18

Page 19: UNIX 101: UNIX For Windows Users

A discourse on the dialectic sublimation inherent in the praxis

of methodological analysis of UNIX philosophy.

•Programs should be designed to work together

•Accept input that isn’t strictly formatted

•Produce output that is nicely formatted

•Should work exclusively with text streams

•Programs should be simple and small

•Do one task, and do that task well

19

Page 20: UNIX 101: UNIX For Windows Users

More Unix Philosophy...

•KISS - Keep It Simple Stupid

•Keep things as simple as possible

•Separate Mechanism From Policy

•Users should be able to decide how a program is to look and behave

•Internals (Mechanism) should not be locked into one policy

20

Page 21: UNIX 101: UNIX For Windows Users

More Unix Philosophy...

•Principle of Least Surprise

•When programs have nothing important to tell you, they will tell you nothing

•Programs should die early and noisily when they die

•There is no “One True Way”™

•Unix is not perfect! But it’s still better than Windows

•Many more philosophical rules than this!

21

Page 22: UNIX 101: UNIX For Windows Users

http://pangea.stanford.edu/computerinfo/unix/overview/advantages.html

- The traditional command line shell interface is user hostile

-- designed for the programmer, not the casual user.

- Commands often have cryptic names and give very little response to tell the user what they are doing. Much use of special keyboard characters - little typos have unexpected results.

- To use Unix well, you need to understand some of the main design features. Its power comes from knowing how to make commands and programs interact with each other, not just from treating each as a fixed black box.

- Richness of utilities (over 400 standard ones) often overwhelms novices. Documentation is short on examples and tutorials to help you figure out how to use the many tools provided to accomplish various kinds of tasks.

22

Page 23: UNIX 101: UNIX For Windows Users

Pleasure You Want. Protection You Trust.

•Everything in Unix is owned by someone

•Files, programs, devices, etc.

•Unix protects users, their data, and their programs from one another

•Regular users are not allowed to do dangerous things to the system

•Distinction between being a “user” and being an “admin”

23

Page 24: UNIX 101: UNIX For Windows Users

Three types of lusers...err users

•Administrative users (aka root)

•Complete control over everything on the system - allowed special privileges

•Can become any user on the system

•Exists on nearly every Unix-based system

•Used for System Maintenance and Administration

24

Page 25: UNIX 101: UNIX For Windows Users

Returning to Normal

•Normal Users (aka you, me, and crazy ivan)

•Allowed to use most of the programs on the system

•Have a special area all to yourself

•Home directory - belongs to you!

•Stores user specific programs, data, and configuration information

•Limited in size on knuth and odin25

Page 26: UNIX 101: UNIX For Windows Users

There’s just [email protected] •System users

•generally used to run daemons

•Why would running a daemon as a regular user or as root be a problem?

•do not usually have home directories

•you cannot log in as one of these users

•examples: bin, lp, mail, pop, sshd, nobody

26

Page 27: UNIX 101: UNIX For Windows Users

Unix Rockstars and their Groupies

•Group: a set of users

•Every user belongs to at least one group: their primary group

•Groups allow for easier management of a system

• students group on turing

•operator group for consultants

27

Page 28: UNIX 101: UNIX For Windows Users

Unix Pre-School:Logging In

•If you don’t have an account on knuth, go see Tim!

•Every user has a username and a password

•Passwords are secret; usernames are not

•Do your best to keep passwords secret!!

•You should try to have as strong a password as you can remember

28

Page 29: UNIX 101: UNIX For Windows Users

g00D P@$$w0rds•Should be at least 8 characters long

•Should include special characters

•Digits, - @ ! # $ % ^ & . , ( ), spaces

•Use a mix upper and lower case letters

•Never use a plain dictionary password!

•elephant is not a good password

•Pass-phrases are better

•I took CS60 1 t00k CS-6o#⇒ 29

Page 30: UNIX 101: UNIX For Windows Users

Sessions of the Heart

•Unix is at its heart a command line OS

•Invented in the days of the teletype

•Physically separated input and processing

•location of the teletype unimportant

•Today we use emulated terminals

•Unix offers graphical environments, but that isn’t where the real power lies

30

Page 31: UNIX 101: UNIX For Windows Users

The Blinking Cursor of DoomWhy learn to use the

command line?

•You have to whether you like it or not

•Simple, Quick, and Powerful

•Efficient

•Superior for certain tasks

•New way for you to think about how to interact with a computer

•Necessary skill to be a Power User

•Gives +4 to your Geek skill; -4 to Social Interaction and Aroma

31

Page 32: UNIX 101: UNIX For Windows Users

Home Sweet Home•When you log in you’ll find yourself in your

home directory

•Located at (on most *nixes)

•/home/username, 1328 Mulberry Drive

•Stores all you personal configuration information

•Is where you’ll keep all your data: homework, documents, etc

•Is your personal space; can do whatever you’d like 3

2

Page 33: UNIX 101: UNIX For Windows Users

Unix Directory Tree

•Unix directories are separated with the / (slash) character

•The Unix directory tree starts at / (root)

•Devices can be located most anywhere on the tree (no Windows A:, C:, D:, stuff)

•The directory tree is filesystem independent

•Do you know which computer your home directory is on?

33

Page 34: UNIX 101: UNIX For Windows Users

Introducing The Shell

•The shell is an interactive program that sits between you and the OS

•Is executed as soon as you log in

•Translates your commands into actions that the computer can perform

•shell == “command interpreter”

•The shell is your new best friend; you’ll have lots of fun together.

34

Page 35: UNIX 101: UNIX For Windows Users

Syntax of a Command

•Any line with a % preceding it is probably happening on the command line

•Jobbies in brackets [~~~] are optional

•Jobbies in angle brackets <~~~> are required

•Command syntax

% command [switches] [arg1] [arg2] ...

(output here)

35

Page 36: UNIX 101: UNIX For Windows Users

Switches•Switches (aka flags) are special arguments

passed in to a program to alter its behavior

•Follow two general styles - Unix and GNU

•Unix: dash ‘-’ followed by a single character

•GNU: Double dash ‘--’ followed by a word

•Programs can take many, many switches

•Newer programs may also have Unix and GNU style switch for the same action

36

Page 37: UNIX 101: UNIX For Windows Users

Arguments•Like switches, variable in number

•Provide some form of data that the program can operate on

•Can be filenames, email address, another command, keywords to search for, patterns, text, random gibberish (or is it?)

•You should get conformable with both switches and arguments

•BE CAREFUL WHAT YOU TYPE !!37

Page 38: UNIX 101: UNIX For Windows Users

Basic Commands

38

Page 39: UNIX 101: UNIX For Windows Users

Basic Commands

39

Page 40: UNIX 101: UNIX For Windows Users

Basic Commands

40

Page 41: UNIX 101: UNIX For Windows Users

Some things to know

•Unix is case sensitive - ‘pwd’ != ‘pWd’

•Unix commands are short

•cp = copy; mv = move; rm = remove

•Unix commands are almost always lower-case

•Switches come on both upper and lower-case

•Often have different meanings! Watch Out!

•Pay attention to special characters

41

Page 42: UNIX 101: UNIX For Windows Users

Ctrl+World = Mwahahaa!!!

•Shortcut sequences are often denoted as C-?, M-?, and ^?, where ? is some key

•C = Ctrl = ^

•M = Meta ~ Alt ~ Option (on Mac only)

•You’ll see this often in documentation, particularly in emacs docs

42

Page 43: UNIX 101: UNIX For Windows Users

Let me outta here!•Exiting or stopping (by which I mean

using) some programs (by which I mean vi) can be a challenge

•Some standard exit shortcuts

C-d : sends EOF to programC-c : interrupts the programC-\ : exits program causing a core dump

•Programs do not have to obey these shortcuts, and may map them to another function.

43

Page 44: UNIX 101: UNIX For Windows Users

Manna from Heaven:

Tab Completion•Wouldn’t it be nice if you didn’t have to

type /home/OneReallyLongName every time?

•You can use the tab key to complete commands and arguments to commands

•Can complete:

•commands, switches, host names, directory names, process names, man pages, and more

44

Page 45: UNIX 101: UNIX For Windows Users

Line Editing

•The up arrow key will cycle back through your command history; pressing down arrow will cycle forward

•The left and right arrow keys will move the position of the cursor so you can insert new characters

•Backspace and delete work as expected

45

Page 46: UNIX 101: UNIX For Windows Users

Line Editing•C-? will delete back

•C-d will delete forward

•C-u will delete the entire line

•C-k will delete the forward from the cursor

•C-l clears the terminal

•C-y will paste the characters you have deleted

46

Page 47: UNIX 101: UNIX For Windows Users

Line Editing•C-a will move to the beginning of the

line

•C-e will move to end of the line

•M-b will move back a word

•M-f will move forward a word

•C-_ will undo the last thing typed

•C-r will allow you to search your command history

47

Page 48: UNIX 101: UNIX For Windows Users

Are You “Special”?•The shell interprets a number of

characters as having special meaning

•Which characters are special?

•# $ * ? [ ] ( ) = | ^ ; < > ` $ “ ‘ \

•Special characters have many uses that we will cover through the course

48

Page 49: UNIX 101: UNIX For Windows Users

Escape From \”Reality\”

•To pass special characters into programs you need to escape them, precede with a \

•\ disables the special meaning of the character

•Can also disable meaning through quoting

•‘xxx’ - all characters disabled

•“xxx” - all but $, ‘, and \ disabled

•\ can also be used to continue a command across multiple lines

49

Page 50: UNIX 101: UNIX For Windows Users

Finding Help:The Larry Page Center for Unix

Addicts

•You can’t teach yourself everything. Admit it, you’re going to need help.

•Resources:

•Google - always try Google first

•Websites - freebsd.org, linuxquestions.org

•Books - Unix Power Tools, FreeBSD Handbook

•People - Staff and Consultants

•QREFs - Documentation provided by CS Dept.

•Mailing Lists and Forums - [email protected]

50

Page 51: UNIX 101: UNIX For Windows Users

Damn Sexist Documentation•the man pages (women get their own

docs)

•are mostly usage guides

•not general references, guides, etc.

•before asking Google, look here

•info pages

•mainly about emacs

•program docs (shared equally by the sexes)

•/usr/share/doc; /usr/doc51

Page 52: UNIX 101: UNIX For Windows Users

Getting Mr. Know-It-All To Be Useful

•Man Sections

•1 - Commands available to users

•2 - Unix and C System Calls

•3 - C Library Routines

•4 - Devices and Device Drivers

•5 - File Formats, Protocols

•6 - Games

•7 - Conventions, Macros, Text Processing

•8 - System Administration Commands52

Page 53: UNIX 101: UNIX For Windows Users

If Only Real Men Had These Switches

53

Page 54: UNIX 101: UNIX For Windows Users

Navigating A Man Page

•You see man output in a pager (by default more, when fixed in less)

•Arrow keys move page up/down left/right

•Space bar - pages down a full screen

•Search using the / key

•/ or n moves to next instance of pattern

•N moves to previous instance

•b key is back/pgup; f key is forward/pgdn

54

Page 55: UNIX 101: UNIX For Windows Users

Working Together

•You have a factory which takes opplar-wheezers and outputs some amazing kolp-shaped nern-draped joggybits.

•You have another factory which accepts these joggybits, and outputs plerk-flavored dasser-bravored fiddlyjinks

•How do you connect the factories...err programs?

55

Page 56: UNIX 101: UNIX For Windows Users

Working Together

•Unix generally runs more than one program at a time (running one is Window’s job)

•Programs are designed to work together, so they need to communicate

•Use I/O mechanisms known as standard in, standard out, and standard error

•By default these either get input from the command line or output to the command line

56

Page 57: UNIX 101: UNIX For Windows Users

Working Together•Standard In (stdin)

•the characters received as input

•Standard Out (stdout)

•the characters that are real program output

•Standard Error (stderr)

•the characters being output as part of any error messages

57

Page 58: UNIX 101: UNIX For Windows Users

Working Together

•Everything in Unix is a file

•devices, directories, sym-links, and what you normally think of as files

•What about stdin, stdout, and stderr?

•What makes a file a “real” file?

58

Page 59: UNIX 101: UNIX For Windows Users

Working Together•Are they files? No, are file

descriptors.

•Treated like files, use read() and write()

•What is read from and written to is managed by the OS

•So, now how do we manage to get two programs to talk?

59

Page 60: UNIX 101: UNIX For Windows Users

Working Together

•We use pipes, which is what std* are

•Data is piped from one program to another

•To pipe stdout (not stderr) use the ‘|’ character

% cmdone args... | cmdtwo args...

•Programs used in this way are called filters

•Learning to use filters is a Unix must

•Writing good filters is even more important

60

Page 61: UNIX 101: UNIX For Windows Users

Misdirection for Redirection

•You can also redirect the output of a program into a file

•Or redirect a program to read stdin from a file

•To redirect stdin:

% command < file

•To redirect stdout (not stderr):

% command > file (may overwrite file)% command >> file (appends to file)6

1

Page 62: UNIX 101: UNIX For Windows Users

What about stderr?

•If stderr is not redirected, it will be printed as normal to the terminal

•To redirect both stdin and stderr:

% billybob |& bubba% homer >& outfile% jethro >>& outfile

•To redirect just stderr:

% marylou 2> errorfile62

Page 63: UNIX 101: UNIX For Windows Users

Complex Redirection•Recall that stdin, etc are just file

descriptors

•We can alter where these descriptors point from the command line

•stdin = 0, stdout = 1, stderr = 2, free 3 to 9

•Examples:

2>&1 (points stderr at stdout)

1>/dev/null (stdout points to oblivion)

2>&1 1>&2 (what does this do?)

3>&2 2>&1 1>&3 (what about this?)

63

Page 64: UNIX 101: UNIX For Windows Users

The Back-Tick

•The back tick is ` (located next to 1 key)

•If you surround a command in back-ticks, the shell will replace the surrounded text with the output of the command

•Examples:

% grep cout `ls *.cpp`% emacs `grep -l error *.c`

•Back-ticks are most useful in shell scripting

64

Page 65: UNIX 101: UNIX For Windows Users

You Ought to Know This By Now

•Aware of Unix Philosophy & History

•Users and Groups

•How to Find Help (*hint* use Google)

•Some (Very) Basic Commands

•Piping, Redirection, and Back-Ticks

•What the Shell Is and Why Its Cool

•A Few Other Tidbits65

Page 66: UNIX 101: UNIX For Windows Users

Processes and Programs

•What is a Program?

•What is a Process?

66

Page 67: UNIX 101: UNIX For Windows Users

The Kernel•What Is The Kernel?

•What Does The Kernel Do?

67

Page 68: UNIX 101: UNIX For Windows Users

Making Forrest Run•Unix is a multi-user and multi-

tasking system

•Need to be able manage processes

•Modern GUIs mitigate this only a bit

•We’ll assume you have one shell session and need to be able to run multiple programs

68

Page 69: UNIX 101: UNIX For Windows Users

Making Forrest Run•Have three types of process groups

•Foreground - process(es) currently receiving keyboard input

•Background - process(es) running, but not receiving keyboard input

•Suspended - processes that aren’t running, but have yet to terminate

•Managing the processes in each of these groups is called “job control”

69

Page 70: UNIX 101: UNIX For Windows Users

Sending The Right Signals

•You suspend a process by sending it a special signal from the keyboard

Suspend = C-z = SIGTSTPInterrupt = C-c = SIGINTQuit = C-\ = SIGQUIT

•These signals are only sent to processes in the foreground group

•Once you suspend the process, you’ll go back to the shell

70

Page 71: UNIX 101: UNIX For Windows Users

Foreground &•When you type in a command at the

shell it runs in the foreground

•To make it run in the background type a ‘&’ after the command

% cmd (running in foreground)% cmd & (running in background)

•To go to a suspended or backgrounded job you use the fg command

71

Page 72: UNIX 101: UNIX For Windows Users

Mid-Level Management

•The jobs command shows which processes you have running in the background

•We can then use the fg command to switch between processes

•Use the bg command to let a suspended process continue in the background

72

Page 73: UNIX 101: UNIX For Windows Users

The Process Family Tree

•Every process on a Unix system has a parent and can have children

•Children are created with the fork() system call - creating a child is known as forking

•Every process is a descendent of init

•Every orphaned process is a child of init

•A zombie is a process which has exited but hasn’t yet been reaped by its parent

73

Page 74: UNIX 101: UNIX For Windows Users

Process Ownership•Each user on the system can own

processes

•Every process must be owned by a user

•To uniquely identify a process it is assigned a number - PID (process id)

•To see all of this information about processes (PID, parent) use the ps command

74

Page 75: UNIX 101: UNIX For Windows Users

How To Be Like Charlie Manson

•kill kill KILL is the command you want

•To kill a process we generally need its PID

•Can get PID from either ps or from top

• top shows bunches of process stats

•What would happen if we typed (as root)...

% kill 1 (init’s PID is always 1)

75

Page 76: UNIX 101: UNIX For Windows Users

Process Priority•Each process has a priority

•The priority determines how much time the process will get on the CPU

•Users can’t change a processes priority, only a superuser and the kernel can do that

•Users can set the niceness of a command

•A higher nice value means that the process is more likely to give up its own time

% nice [-n N] cmd (N = 0 to 19)76

Page 77: UNIX 101: UNIX For Windows Users

Useful Programs

77

Page 78: UNIX 101: UNIX For Windows Users

Useful Programs

78

Page 79: UNIX 101: UNIX For Windows Users

Useful Programs

79

Page 80: UNIX 101: UNIX For Windows Users

Useful Programs

80

Page 81: UNIX 101: UNIX For Windows Users

Useful Programs

81

Page 82: UNIX 101: UNIX For Windows Users

File Ownership

•Files also follow a security model

•Each file has an owner and a group

•The owner is the user that created it

•The group is (generally) the primary group of the user

•Each file has three sets of permissions

•User, group, and others (everyone else on the system)

82

Page 83: UNIX 101: UNIX For Windows Users

File Permissions

•Each file has permissions for read, write and execute

•Each of these permissions apply to user, group, and others

•So permissions look like

rwx | rwx | rwxuser | group | others

83

Page 84: UNIX 101: UNIX For Windows Users

Changing Ownership

•Only the owner and superuser can change the ownership of a file

chown

chgrp

84

Page 85: UNIX 101: UNIX For Windows Users

Changing File Permissions:

Why You Can’t touch her.jpg

•Use chmod to change file permissions

chmod

85

Page 86: UNIX 101: UNIX For Windows Users

Special Files:They ride the system bus

•Directories

•Permissions mean different things

•r - can list contents with ls

•w - can create a file inside directory

•x - can access a file inside directory

86

Page 87: UNIX 101: UNIX For Windows Users

I Can’t See .deadpeople

•Dot-Files are files with a ‘.’ as the first character of the file’s name (geewiz!!)

•You can see these files with ls -a

•Generally contain configuration information

•Examples: .zshrc, .emacs, .xinitrc

./ and . : the current directory

../ and .. : the parent directory

87

Page 88: UNIX 101: UNIX For Windows Users

~ Sweet ~•‘~’ is referred to as a tilde (TILL-day)

•~ is a shortcut referring to your home directory

• ~username refers to that users home directory

•Example:

~mkegel = /home/mkegel (on knuth)~mkegel = /Users/mkegel (on shadow)

88

Page 89: UNIX 101: UNIX For Windows Users

•A path is either an absolute or relative path

•Absolute paths begin at / (root)

•Relative paths begin at the current working directory (cwd)

•Example (absolute): /home/lush/drinks/vodka.tex~/drinks/vodka.tex

•Example (relative): ./drinks/vodka.tex../wino/drinks/maddog.tex drinks/vodka.tex

89

Page 90: UNIX 101: UNIX For Windows Users

File Links•A link allows you to refer to one file, by

a name other than what it has

•Ex. Could refer to /billy/joe as /billy/bob

•When you access /billy/bob the OS transparently redirects you to /billy/joe

•Can link to both a regular file or to a directory

•Two types of links: hard-links and symbolic-links (aka symlinks)

90

Page 91: UNIX 101: UNIX For Windows Users

Types of Links•Hard-links

•Cannot refer to a directory•Cannot cross file systems•Take up virtually no memory•Are essentially a different name for the

same file

•Symlinks•Can do what hard-links cannot•Are a real file on disk (this can present

problems)91

Page 92: UNIX 101: UNIX For Windows Users

Creating Links

92

Page 93: UNIX 101: UNIX For Windows Users

The Glob•File globs (aka wildcards) allow you to

refer to a group of files whose names match a specific pattern

•Globs are different than Unix Regexs

•Globing is provided by the shell

•Why is it a good thing (or a bad one) for globs to be expanded by the shell?

93

Page 94: UNIX 101: UNIX For Windows Users

Standard Globs* - matches anything, except dot-files

** - search recursively

*** - search recursively, follow symlinks

? - matches a single character

[a-z] - match a single character in the

specified range

[^a-z] - match a character NOT in the range

(x|y|z)- match either x or y or z

{a,b,c}- expands to a, b, c

94

Page 95: UNIX 101: UNIX For Windows Users

Unix Directories•The organization of programs and files in

the Unix Hierarchy is interesting

•Programs are grouped by how critical they are to the operation of the system

•In general there is a correct location for programs, libraries, and configuration files to go

•Whether or not these “rules” are followed is up to the providers of the system

95

Page 96: UNIX 101: UNIX For Windows Users

Not so much rules as guidelines/home - user home directories

/bin - user critical programs/dev - block and character device files/etc - system configuration files/sbin - system critical programs/tmp - temporary files/usr - general user programs/var - variable length files (log files)/lib - shared libraries/opt - larger static packages/boot - kernel image and other boot files/mnt - mount point for devices

96

Page 97: UNIX 101: UNIX For Windows Users

Some special devices• /dev/null

•Is a sink for output• /dev/zero

•Ever want to have an infinite stream of zeros? Here’s your chance!

• /dev/random and /dev/urandom

•Both output a random stream of information

• /dev/random draws from the entropy pool

• /dev/urandom is actually pseudo-random• /dev/pr0n

•An infinite stream of porn97

Page 98: UNIX 101: UNIX For Windows Users

Environment and Shell Variables

•The shell keeps track of a number of variables that hold useful information

•Programs that you run from the shell are able to access these variables

•Env. variables are inherited by all the shells you may have; shell variables are local to each instance

•Environment variables are named (by convention)in all CAPS; shell variables are lower-case

98

Page 99: UNIX 101: UNIX For Windows Users

Common Env. Variables•Use the printenv and set commands to

see what variables are set and their values

PATH - directory list searched for commands

MANPATH - directory list; for man pages

PS1 and PS2 - your prompt definition

PAGER - pager used to open man pages

EDITOR and VISUAL - preferred text editor

HOSTNAME - name of computer logged in to

UID and GID - your user and group IDs

99

Page 100: UNIX 101: UNIX For Windows Users

Setting Env. Variables

•You use the export command in zsh to set environment variables

•You can see the value of a specific variable by using the echo command

100

Page 101: UNIX 101: UNIX For Windows Users

Setting Env. Variables

•Zsh reads many different configuration files, some of them are:

~/.zshrc ~/.zprofile ~/.zlogin

•Read through these files!

101

Page 102: UNIX 101: UNIX For Windows Users

•To reduce typing, alias a long and/or repeated command(s) to a single short command

102

Page 103: UNIX 101: UNIX For Windows Users

Altering the Default

Permissions•By default when you create a file, ALL

the rwx permissions are set to ON

•Your umask sets what permissions are to be turned OFF

•Some good default umasks: 022, 076

•Some bad default umasks: 755, 701

103

Page 104: UNIX 101: UNIX For Windows Users

su and sudo•These two programs allow you to execute

programs as a superuser (or another user)

•work by changing your UID and GID

•With su you have to know that users password

•With sudo you generally use your own password

• sudo is flexible; su is not

• sudo can control which programs are executed as which users on which systems by which users

104

Page 105: UNIX 101: UNIX For Windows Users

Editing /etc/sudoers

•The privileges that sudo grants are stored in a regular text file (/etc/sudoers) and is editing by the visudo program

•Basic syntax for an entry is:

USER HOST = [(RUN_AS_USER)] CMDS

•Some examples:

joe turing = (root) /sbin/some_cmd

%group ALL = (root) NOPASSWD: /bin/cmd

105

Page 106: UNIX 101: UNIX For Windows Users

Everything You Always Wanted to Know About

Mounting Drives, But Were Afraid to Ask•In Unix devices (hard drives, cameras,

etc.)are managed by the superuser

•Devices are “mounted” at some point on the file system; they can then be accessed

•You use the mount command to mount any type of device - hard drives, usb devices, etc.

•Improper mounting can leave behind child processes

106

Page 107: UNIX 101: UNIX For Windows Users

devices•Device nodes are located in /dev

•Linux device names, examples

•hda3 (first hard drive, third partition)

•sdb2 (SCSI device)

•input/mouse0 (mouse on my system)

•You always mount a device to a directory

107

Page 108: UNIX 101: UNIX For Windows Users

mount and umount

•Use these programs to mount and unmount filesystems (generally need to be root to do so, however)

108

Page 109: UNIX 101: UNIX For Windows Users

/etc/fstab•Informs the system of which devices

are hooked up to your system

•Can mount devices at boot (or not), how they are mounted, other options

•Can automagically mount a device if the mount point is in /etc/fstab

•DO NOT EVER FUBAR THIS FILE!!

•or you will be unhappy and have to use ed

109

Page 110: UNIX 101: UNIX For Windows Users

cron The Punctual Warrior

•cron - daemon that schedules tasks for execution

•entries created/modified with the crontab command

•Can schedule based on:

mins hrs day-of-month month weekday cmd

•Can specify a single entry, a range, a list, or give the all wildcard (*) for a specific time-slot

110

Page 111: UNIX 101: UNIX For Windows Users

A Better Replacement• Web Browser - Firefox, Konqueror• Text Editor - jEdit, emacs, vi• Word Processor - abiword, Open Office• Spreadsheet - gnumeric, Open Office• Music Player - xmms, amarok• Movie Player - vlc, totem, xine, mplayer• Terminals - eterm, xterm, rxvt, konsole• Mail - Thunderbird, pine, mutt• PDF - xpdf, kpdf, gpdf• FTP - gftp, ncftp, lftp• CD Burner - k3b• AIM - gaim, kopete• Bit Torrent - Azureus• File Manager - Nautilus, Konqueror• Spell Checkers - ispell, aspell• Desktops Env’s - GNOME, KDE• Window Managers - fluxbox, xfce, enlightenment

111

Page 112: UNIX 101: UNIX For Windows Users

Other Useful Programs•WINE - allows you to run many

Windows executables on Linux

•Cygwin - allows you to run some Linux programs on Windows

•Samba - lets Linux use Windows networks

•jEdit, Emacs, vi - powerful text editors

•Only one thing to know - don’t use vi

•Shell Scripting, Perl, Python

112

Page 113: UNIX 101: UNIX For Windows Users

Regular Expressions

•The most nifty, and geekifying, Unix thing ever...

•makes parsing of complicated input simple, easy, and efficient.

113

Page 114: UNIX 101: UNIX For Windows Users

tr

•Tool to translate characters; like a global search-and-replace from the command line

114

Page 115: UNIX 101: UNIX For Windows Users

screen

•Nifty tool that allows you leave shells open (and programs running) on which ever machine you’re logged into

115

Page 116: UNIX 101: UNIX For Windows Users

Thank you’s•I’d like to thank (in no particular

order):

Ran Libeskind-HadasMelissa O’NeillGeoff KuenningMike ErlingerChris StoneTitus Wintersand especially those willing to sit through these lectures....and anyone else I forgot...1

16