UNIX 101 UNIX For Windows Users Lecture 1

  • Slides: 116
Download presentation
UNIX 101: UNIX For Windows Users Lecture 1 9 September 2005 Sponsored by ACM

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

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 2 all of us.

Just Who Do We Think We Are? • Mark Kegel - Tall Guy with

Just Who Do We Think We Are? • Mark Kegel - Tall Guy with Black Hair • mkegel@cs. hmc. edu • Marshall Pierce - Broad Shouldered Guy • mpierce@cs. hmc. edu 3

And Just What Do We Think We’re Doing? • We are here to teach

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 yourself about Unix. • We’re on a mission from God. 4

Never Mind Us, Who Are You People? • Students who have no experience with

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

Some Reasons to Learn About Unix • Growth of Linux • OS X is

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 l 33 t h 4 X 0 r • BTW, you will always be teh newb 6

Some Better Reasons to Learn About Unix • I want to show my girlboy-friend

Some Better Reasons to Learn About Unix • I want to show my girlboy-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 (CS 60 or above) from the CS department 7

The Best Reasons To Learn About Unix. . . • As a CS major

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

To Make This Perfectly Clear. . . • We will NOT teach you how

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

Down To Business. . . • Computing Resources Available To You • Terminal Room:

Down To Business. . . • Computing Resources Available To You • Terminal Room: Beckman B 102 • Mac minis (aren’t they just so cute) • Printer: gute. cs. hmc. edu • Graphics Lab: Beckman B 105 • some old’n’busted computers 10

 • AC and LAC Labs • Windows and Mac Computers • Printers: Odie

• 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

All-Campus Servers • odin. ac. hmc. edu • RHEL server; Student POP server •

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

CS Dept. Servers • turing. cs. hmc. edu (sparc) • primary work server -

CS Dept. Servers • turing. cs. hmc. edu (sparc) • primary work server - you’ll do most • • of your work from here knuth. cs. hmc. edu (x 86) our new server - where you ought to be working when you can wilkes. cs. hmc. edu (x 86) alternate work server • • • muddcs, ark, cortana, durandal 13

The Doctor Will See Youseveral Now • Mudd employs whose jobs entail fixing computer

The Doctor Will See Youseveral Now • Mudd employs 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

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

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

When Hippies walked the earth. . . • Ken Thomson • Invented UNICS in

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 blur 16

Unix Today • Fundamentally multi-user and multi-tasking • Programmer’s and tinkerer’s environment • Support

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

The Idea of Unix? • Unix is more than an OS, it is •

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

A discourse on the dialectic sublimation inherent in the praxis of methodological analysis of

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

More Unix Philosophy. . . • KISS - Keep It Simple Stupid • Keep

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

More Unix • Principle of Least Surprise Philosophy. . . • When programs have

More Unix • Principle of Least Surprise Philosophy. . . • 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! • Many more philosophical rules than this! But it’s still better than Windows 21

http: //pangea. stanford. edu/computerinfo/unix/overview/advantages. html - The traditional command line shell interface is user

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 22 kinds of tasks.

Pleasure You Want. Protection You Trust. • Everything in Unix is owned by someone

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

Three types of lusers. . . err users • Administrative users (aka root) •

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

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

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 odin 25

There’s just nobody@home. com • System users • generally used to run daemons •

There’s just nobody@home. com • 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

Unix Rockstars and their Groupies • Group: a set of users • Every user

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

Unix Pre-School: Logging In • If you don’t have an account on knuth, go

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

g 00 D P@$$w 0 rds • Should be at least 8 characters long

g 00 D P@$$w 0 rds • 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 CS 60 ⇒ 1 t 00 k CS-6 o# 29

Sessions of the Heart • Unix is at its heart a command line OS

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

The Blinking Cursor of Doom Why learn to use the command line? • You

The Blinking Cursor of Doom Why 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

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

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 32

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

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 33 on?

Introducing The Shell • The shell is an interactive program that sits between you

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

Syntax of a Command • Any line with a % preceding it is probably

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] [arg 1] [arg 2]. . . (output here) 35

 • Switches (aka flags) are special Switches arguments passed in to a program

• Switches (aka flags) are special Switches 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 36

Arguments • Like switches, variable in number • Provide some form of data that

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

Basic Commands 38

Basic Commands 38

Basic Commands 39

Basic Commands 39

Basic Commands 40

Basic Commands 40

to !=know • Some Unix is casethings sensitive - ‘pwd’ ‘p. Wd’ • Unix

to !=know • Some Unix is casethings sensitive - ‘pwd’ ‘p. Wd’ • Unix commands are short • cp = copy; mv = move; rm = remove • Unix commands are almost always lowercase • Switches come on both upper and lowercase • Often have different meanings! Watch Out! • Pay attention to special characters 41

Ctrl+World = Mwahahaa!!! • Shortcut sequences are often denoted as C-? , M-? ,

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

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

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 program C-c : interrupts the program C- : exits program causing a core dump • Programs do not have to obey these shortcuts, and may map them to another function. 43

Manna from Heaven: Tab Completion • Wouldn’t it be nice if you didn’t have

Manna from Heaven: Tab Completion • Wouldn’t it be nice if you didn’t have to type /home/One. Really. Long. Name 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

Line Editing • The up arrow key will cycle back through your command history;

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

Line Editing • C-? will delete back • C-d will delete forward • C-u

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

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

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

Are You “Special”? • The shell interprets a number of characters as having special

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

Escape From ”Reality” • To pass special characters into programs you need to escape

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 49

Finding Help: The Larry Page Center for Unix • You can’t teach yourself everything.

Finding Help: The Larry Page Center for Unix • You can’t teach yourself everything. Admit it, you’re going to. Addicts need help. • Resources: • Google - always try Google first • Websites - freebsd. org, linuxquestions. org • Books - Unix Power Tools, Free. BSD • • • Handbook People - Staff and Consultants QREFs - Documentation provided by CS Dept. 50 Mailing Lists and Forums - linux-

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

Damn Sexist • the Documentation 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/doc 51

Getting Mr. Know-It. All To Be Useful • Man Sections • 1 - Commands

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 52 8 - System Administration Commands

If Only Real Men Had These Switches 53

If Only Real Men Had These Switches 53

Navigating A Man • You see man. Page output in a pager (by default

Navigating A Man • You see man. Page 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 54

Working Together • You have a factory which takes opplarwheezers and outputs some amazing

Working Together • You have a factory which takes opplarwheezers and outputs some amazing kolp-shaped nern-draped joggybits. • You have another factory which accepts these joggybits, and outputs plerkflavored dasser-bravored fiddlyjinks • How do you connect the factories. . . err programs? 55

Working Together • Unix generally runs more than one program at a time (running

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

Working Together • Standard In (stdin) • the characters received as input • Standard

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

Working Together • Everything in Unix is a file • devices, directories, sym-links, and

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

Working Together • Are they files? No, are file descriptors. • Treated like files,

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

Working Together • We use pipes, which is what std* are • Data is

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

Misdirection for Redirection • You can also redirect the output of a program into

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) 61

What about stderr? • If stderr is not redirected, it will be printed as

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> errorfile 62

Complex Redirection • Recall that stdin, etc are just file descriptors • We can

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 1>/dev/null 2>&1 1>&2 (points stderr at stdout) (stdout points to oblivion) (what does this do? ) 3>&2 2>&1 1>&3 (what about this? ) 63

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

The Back-Tick • The back tick is ` (located next to 1 key) • If you surround a command in backticks, 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

You Ought to Know This By Now • Aware of Unix Philosophy & History

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 Tidbits 65

Processes and Programs • What is a Program? • What is a Process? 66

Processes and Programs • What is a Program? • What is a Process? 66

The Kernel • What Is The Kernel? • What Does The Kernel Do? 67

The Kernel • What Is The Kernel? • What Does The Kernel Do? 67

Making Forrest Run • Unix is a multi-user and multi-tasking system • Need to

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

Making Forrest Run • Have three types of process groups • Foreground - process(es)

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

Sending The Right Signals • You suspend a process by sending it a special

Sending The Right Signals • You suspend a process by sending it a special signal from the keyboard Suspend = C-z = SIGTSTP Interrupt = C-c = SIGINT Quit = 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

Foreground & • When you type in a command at the shell it runs

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

Mid-Level Management • The jobs command shows which processes you have running in the

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

The Process Family Tree • Every process on a Unix system has a parent

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

Process Ownership • Each user on the system can own processes • Every process

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

How To Be Like Charlie Manson • kill KILL is the command you want

How To Be Like Charlie Manson • 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

Process Priority • Each process has a priority • The priority determines how much

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 76

Useful Programs 77

Useful Programs 77

Useful Programs 78

Useful Programs 78

Useful Programs 79

Useful Programs 79

Useful Programs 80

Useful Programs 80

Useful Programs 81

Useful Programs 81

File Ownership • Files also follow a security model • Each file has an

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

File Permissions • Each file has permissions for read, write and execute • Each

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 user | group | others 83

Changing Ownership • Only the owner and superuser can change the ownership of a

Changing Ownership • Only the owner and superuser can change the ownership of a file chown chgrp 84

Changing File Permissions: Why You Can’t touch her. jpg • Use chmod to change

Changing File Permissions: Why You Can’t touch her. jpg • Use chmod to change file permissions chmod 85

Special Files: They ride the system bus • Directories • Permissions mean different things

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

I Can’t See. deadpeople • Dot-Files are files with a ‘. ’ as the

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

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

~ 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

 • A path is either an absolute or • • • relative path

• 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

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

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

Types of Links • Hard-links • Cannot refer to a directory • Cannot cross

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

Creating Links 92

Creating Links 92

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

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

** Standard Globs - search recursively *** - search recursively, follow symlinks ? -

** Standard Globs - search recursively *** - search recursively, follow symlinks ? - matches a single character * - matches anything, except dot-files [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

Unix Directories • The organization of programs and files in the Unix Hierarchy is

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

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

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

 • Some special devices /dev/null • Is a sink for output • /dev/zero

• 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/pr 0 n • An infinite stream of porn 97

Environment and Shell Variables • The shell keeps track of a number of •

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

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

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 PS 1 and PS 2 - 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

Setting Env. Variables • You use the export command in zsh to set environment

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

Setting Env. Variables • Zsh reads many different configuration files, some of them are:

Setting Env. Variables • Zsh reads many different configuration files, some of them are: ~/. zshrc ~/. zprofile ~/. zlogin • Read through these files! 101

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

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

Altering the Default Permissions • By default when you create a file, ALL the

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

su and sudo • These two programs allow you to execute programs as a

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 can control which programs are executed as which users on which systems by which users 104 sudo

Editing /etc/sudoers • The privileges that sudo grants are stored in a regular text

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

Everything You Always Wanted to Know About Mounting Drives, But Were • In Unix

Everything You Always Wanted to Know About Mounting Drives, But Were • In Unix devices (hard drives, cameras, Afraid to Ask 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 106

devices • Device nodes are located in /dev • Linux device names, examples •

devices • Device nodes are located in /dev • Linux device names, examples • hda 3 (first hard drive, third partition) • sdb 2 (SCSI device) • input/mouse 0 (mouse on my system) • You always mount a device to a directory 107

mount and umount • Use these programs to mount and unmount filesystems (generally need

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

/etc/fstab • Informs the system of which devices are hooked up to your system

/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

cron The Punctual Warrior • cron - daemon that schedules tasks for execution •

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 weekday cmd • Can specify a single entry, a range, a list, or give the all wildcard (*) for a specific time-slot 110

A Better Replacement • • • • • Web Browser - Firefox, Konqueror Text

A Better Replacement • • • • • Web Browser - Firefox, Konqueror Text Editor - j. Edit, 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 - k 3 b 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

Other Useful • WINE - allows you to run many Programs Windows executables on

Other Useful • WINE - allows you to run many Programs Windows executables on Linux • Cygwin - allows you to run some Linux programs on Windows • Samba - lets Linux use Windows networks • j. Edit, Emacs, vi - powerful text editors • Only one thing to know - don’t use vi • Shell Scripting, Perl, Python 112

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

Regular Expressions • The most nifty, and geekifying, Unix thing ever. . . • makes parsing of complicated input simple, easy, and efficient. 113

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

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

screen • Nifty tool that allows you leave shells open (and programs running) on

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

Thank you’s • I’d like to thank (in no particular order): Ran Libeskind-Hadas Melissa

Thank you’s • I’d like to thank (in no particular order): Ran Libeskind-Hadas Melissa O’Neill Geoff Kuenning Mike Erlinger Chris Stone Titus Winters and especially those willing to sit through these lectures. . and anyone else I 116 forgot. . .