Unformatted text preview:

Unix Programming Environment Objective To introduce students to the basic features of Unix and the Unix Philosophy collection of combinable tools and environment that supports their use Basic commands File system Shell Filters wc grep sort awk Many of the examples for this lecture come from the UNIX Prog Env and AWK books shown see lecture outline for full references 1 1 Getting Started Getting a CS account Lab in Univ Crossings 151 tux cs drexel edu queen cs drexel edu lab machines and tux running linux queen running solaris http www cs drexel edu page php name accounts html ssh part of Drexel CD http www drexel edu IRT services software cygwin www cygwin com loggin on and out Command Line Interface jjohnson ws44 jjohnson echo hello hello jjohnson ws44 jjohnson date Tue Nov 30 05 24 34 EST 2004 jjohnson ws44 jjohnson uptime 05 24 40 up 8 days 5 19 6 users load average 1 22 1 26 1 63 jjohnson ws44 jjohnson who ummaycoc pts 0 Nov 23 09 56 node4 uphs upenn edu jmn27 pts 1 Nov 30 01 06 mst cs drexel edu kn42 pts 2 Nov 30 02 09 n2 202 96 resnet drexel edu jjohnson pts 4 Nov 30 05 23 n2 19 88 dhcp drexel edu ks347 pts 6 Nov 30 02 59 pcp04354303pcs glstrt01 nj comcast net jmn27 pts 3 Nov 30 01 33 mst cs drexel edu Command Line Interface jjohnson ws44 jjohnson finger jmn27 Login jmn27 Name John Novatnack Directory home jmn27 Shell usr local bin tcsh On since Tue Nov 30 01 06 EST on pts 1 from mst cs drexel edu 3 hours 38 minutes idle On since Tue Nov 30 01 33 EST on pts 3 from mst cs drexel edu 3 hours 38 minutes idle Mail last read Tue Jan 4 15 53 2005 EST Plan hey i m john Command Line Interface options usually designated with who q Getting Help manual man who info info who internet The linux documentation project http www tldp org safari online friends and others man man who WHO 1 User Commands WHO 1 NAME who show who is logged on SYNOPSIS who OPTION FILE ARG1 ARG2 DESCRIPTION a all same as b d login p r t T u q count all login names and number of users logged on SEE ALSO The full documentation for who is maintained as a Texinfo manual If the info and who programs are properly installed at your site the command info coreutils who should give you access to the complete manual info info who File coreutils info Node who invocation Prev users invocation Up User information who Print who is currently logged in who prints information about users who are currently logged on Synopsis who OPTION FILE am i If given no non option arguments who prints the following information for each user currently logged on login name terminal line login time and remote hostname or X display If given one non option argument who uses that instead of etc utmp as the name of the file containing the record of users logged on etc wtmp is commonly given as an argument to who to look at who has previously logged on File System Organized into a tree of directories starting at the root bin dev etc usr tmp me you them junk stuff File System absolute and relative paths usr me stuff and Commands for traversing file system pwd cd ls Commands for viewing files cat more less File System absolute and relative paths usr me stuff and Commands for traversing file system pwd cd ls Commands for viewing files cat more less od File System Commands for copying removing and linking files cp mv rm ln Commands for creating and removing directories mkdir rmdir Archiving directory structure tar gzip gunzip File System File permissions owner group world everyone else chgrp chown ls l chmod File System jjohnson ws44 winter ls l total 24 drwxr xr x 7 jjohnson users 80 Jan 3 2005 cs265 rw 1 jjohnson users 8258 Jan 3 2005 cs265 html rw r r 1 jjohnson users 8261 Jan 3 2005 cs265 html jjohnson ws44 winter chmod 644 cs cs265 cs265 html cs265 html jjohnson ws44 winter chmod 644 cs265 cs265 html cs265 html jjohnson ws44 winter chmod 644 cs265 html jjohnson ws44 winter ls l total 24 drwxr xr x 7 jjohnson users 80 Jan 3 2005 cs265 rw r r 1 jjohnson users 8258 Jan 3 2005 cs265 html rw r r 1 jjohnson users 8261 Jan 3 2005 cs265 html shell command interpreter bash sh csh bashrc profile PATH and shell variables metacharacters history and command completion file redirection pipes process management editor A text editor is used to create and modify files The most commonly used editors in the Unix community are vi improved vi vim and emacs You must learn at least one of these editors you can get started quickly use info and go through a tutorial and learn more as you start using it Tutorial for vim vimtutor filters Programs that read some input perform a simple transformation on it and write some output Examples wc tr grep egrep sort cut uniq head tail grep search for lines matching pattern in specified files In the simplest case search for given string file and matching line are shown grep main cpp assign31 cpp The main program queries the user to provide assignments of truth values to the assign31 cpp int main bestval cpp int main bestval cpp string remainder read remainder of line bestval cpp getline cin remainder max cpp int main set cpp int main tstr cpp int main More generally regular expressions are used for patterns Regular Expressions There are three operators used to build regular expressions Let R and S be regular expressions and L R the set of strings that match R Union R S L R S L R L S Concatenation RS L RS rs r R and s S Closure R L R R RR RRR Regular Expressions a ab a ab c bc a a b ab a bc d letter a b c z A B C Z digit 0 1 2 3 4 5 6 7 8 9 letter letter digit Unix Syntax for Regular Expressions Many Unix commands grep egrep awk editors use regular expressions for denoting patterns The notation is similar amongst commands though there are a few differences see man pages It pays to get comfortable using regular expressions see examples at the end grep and egrep Regular Expressions decreasing order of precedence c c n r r r1r2 r1 r2 r r any non special character matches itself turn off any special meaning of character c beginning of line end of line any single character any one of the characters in ranges like a z are legal any single character not in ranges are legal what the nth character matched grep only zero or more occurrences of regular expression r one or more occurrences of regular expression r regular expressions r1 followed by r2 regular expressions r1 or r2 egrep only tagged regular expression r …


View Full Document

DREXEL CS 265 - Unix Programming Environment

Loading Unlocking...
Login

Join to view Unix Programming Environment and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Unix Programming Environment and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?