Class Introduction
Agenda Syllabus Topics Text etc
Homework/Lab File Format Word processor on PCs is OpenOffice, use “Save As” to convert to.doc I can read.pdf,.doc,.docx or.odt Please no screen shots in homework, plain text is fine! Assignment says “Provide References”, please do so or it’s points off
Intro To Linux
Unix History Developed at Bell Labs in the late 1960s. First O/S to run on multiple hardware types Original Open Source!
Linux History Written by Linux Torvalds as a free clone of Minix –Used the GNU tool chain with a custom kernel.1 came out in 9/ = 10/1991 Current Stable version: (as of 3/15/2012) content/uploads/unix_family_history_tree_1600x 1200.jpg
Timeline
Linux GUIs KDE = K Desktop Environment –Used QT which wasn’t “free” GNOME = GNU Object Model Environment –Totally “free” desktop environment There are tons of others
CLI CLI = Command Line Interface Typically a shell, much more powerful than a GUI but not near as user-friendly
File System File System Layout
Some Useful Commands ls – lists files cd – change directories cp – copy files mv – move files rm – remove (or delete) files etc, etc, etc
Bash
Acronym for Bourne Again Shell Default for Linux, available for most commercial Unixes. Advanced Bash Scripting: html
What does a shell do? Reads input Breaks input into tokens Use those tokens to create commands Do shell expansion, i.e. parse *,., ?, etc Check for redirection Return an exit status
Basic Token Parsing Typical command: –ls –a -l a* ls is a command -a -l are arguments for the command - = 1 letter arguments -- = human readable arguments a* gets expanded to match all files beginning with a in the current directory
Shell startup Reads the following in order to initialize shell variables: –/etc/profile –/etc/bashrc –Run the first one of these: ~/.bash_profile ~/.bash_login ~/.profile ~/.bashrc
Useful Variables HISTSIZE = # of commands stored PWD = the current directory OLDPWD = your old directory PATH = the path that’s searched for commands PS1 = your prompt Access via commands: set or env
Variable Rules Typically UPPERCASE, but don’t have to be No space when asssigning! –VAR=First (works) –VAR = First (does not)
Aliases New name for a command, use alias to create, unalias to remove alias rm=“rm –i” – always prompt on rm
Expansion Brace or {} – used to generate lists Tilde or ~ - shorthand for home directory Command or `` - take the output of what’s in the `` and use it Pattern Matching or Regular Expression – foo* match everything that starts with foo
Special Characters \, $, ‘’, “”, `` - are the specials \ (or escape) removes special meaning $ access variables ‘’ means literal output “” means mostly literal output `` stores output from a command
Redirection I/O is typically keyboard/screen, shells allow redirection | means pipe one command to another > is overwrite >> is append < is redirect input << read until tag
Other features Tab completion History Command Line Editing (defaults to emacs, can use vi) Help
Regular Expressions
What are they? A regular expression is a string of characters that matches a pattern of some kind. –000 –01010 –aabbcc –Stuart Usually used with meta-characters
Metacharacters. = match any character exactly 1 time * = match 0 or more characters + = match 1 or more characters ^ = match at start of line $ = match at end of line
Metacharacters II [chars] = match chars in bracket (not PATTERN) [^chars] = ignore chars in bracket (not PATTERN) \ = escape special characters, i.e. \^ | = or choices {this|or|that} {n} = match at least n occurances {n,m} = match at least n but not more than m
Metacharacters III: the examples ^[0-9] – matches lines that start with digits b.d – matches anything with a b followed by any character and a d (such as bad, bed, bid, bcd) [a-z] – matches any lower case letter [a-zA-Z] – matches any letter [a-z]\{1,3\} – matches any string of 1 to 3 letters (ask, eee, q, be, bet, etc) [tT][iI][fF]\{1,2\} – matches a t or T followed by an i or I followed by 1 or 2 f or Fs [a-z]\{3\}|[A-Z]\{3\} – matches any three letters as long as all three are upper case or lower case
RegExp and ls Can’t use ^, { }, +, or $, but most everything else works –ls *[0-9]* = match files with 0-9 in name. means match., not a single character!
grep
RegExp and grep grep = Grab REgular exPressions 4 different versions on Linux: –grep – limited regexp set –egrep – largest regexp set (also grep –E) –rgrep – recursive grep (also grep -r) –fgrep (fast grep) – very limited regexp set metacharacters ( $, *, [, ^, |, (, ), \ ) translated literally!
Uses for grep Your company just got bought. How many files have the old company in them on the web server? What’s a 7 letter word for “Queens of Russia that starts with ts and ends with an a? How many files got changed in August of last year?
Useful grep arguments -c = shows a count of matches in the file(s) -n = shows what lines the matches are on -l = just file names -v – negate the search -i – ignore case
More useful grep arguments --color=# - display in color –# = always, color, none
Advanced grep arguments -A, -B, -C = context to search –-A # = # lines after –-B # = # lines before –-C # = # lines around --regexp=PATTERN = Use PATTERN as the pattern; useful to protect patterns beginning with -.
Finding Words \< = blank space at beginning of word \> = blank space at end of word -w = find word, has to have white space