------------------------ Week 3 Notes for CST8129 ------------------------ -Ian! D. Allen - idallen@idallen.ca *** Keep up on your readings (Course Outline: average 5 hours/week homework) Remember - knowing how to find out an answer is more important than memorizing the answer. Learn to fish! RTFM! (Read The Fine Manual) Reminder: Midterm Test #1 in Week #5 (see the course home page). X11 cut and paste - left mouse button drags and puts in clipboard - middle button pastes - right button extends selection Man pages - "man -k" (or "apropos") is very useful to find command names! - section 1 is commands - know how to read man pages (man page syntax meaning) - See Notes file: man_page_RTFM.txt Searching for items in the Unix manual pages (RTFM) New commands learned this week: grep head tail cal du file hostname mkdir/rmdir more mv printenv sort also: grep -v, sort -r -n - grep pattern file - crude Data Mining: selecting content by looking for lines - using grep on course notes: grep ssh ~alleni/public_html/teaching/cst8129/05f/notes/*.txt - grep -v finds lines that do *not* contain the pattern - see example in man_page_RTFM.txt - head(-5) tail(-5) - apropos(man -k) - cal(try 9 1752) - wc(-lwc) ls(-ld) grep(-v) sort(-nr) rm(-r) - "sort" sorts all its arguments (together) to standard output - the files themselves are not changed - never use redirection to direct output into an input file! - "sort" sorts alphabetically (usually ASCII collating order) - need to use -n option to sort by leading number - "ls -ld" is needed to see the attributes of a directory (instead of seeing the attributes of the directory contents) - use "rm -r" to remove recursively a directory and all contents Terminal - See Notes file terminal.txt - backspace key should erase one char - command: stty erase ^? - command: stty erase ^H - EOF - End Of File from keyboard: ^D - ASCII EOT: send the current partial line to the process Note: when ^D is typed at the very *start* of a line of input: signal End-Of-File (EOF) to current process - EOF ^D vs. Interrupting Processes ^C - not the same! $ sort - note difference between ^C and ^D $ wc - note difference between ^C and ^D $ cat - less difference - Unix line ends are \n characters (not \r or \r\n) $ echo hi | wc -c # prints 3 not 2 because of \n at end Learn various ways of getting out of programs - See Notes file miscellaneous.txt Output redirection: - See Notes file redirection.txt - you can only redirect what you can see - if you see nothing, adding redirection will create an empty file! - redirection is done first and then removed from command line - it is never passed to the command; it is never a command argument $ date ; date >out $ cp a b ; cp a b >out $ head /etc/passwd >out ; sort out ; sort out >out $ rm out >out $ date >out ; ls -l out >out - appending to files is done using >> You can tell the shell to redirect the input and/or output of any command: see Notes file redirection.txt - simple output redirection: sort /etc/passwd >out - simple input redirection: sort out - simple pipe: ls /usr/bin | wc - "standard output" is usually your screen - "standard input" is usually your keyboard - redirection is never counted as arguments to a command - the shell does the redirection and removes the syntax - the command never sees any of the redirection syntax Review: difference between command names, options, and file names $ date >wc ; >wc date ; wc -wc wc >ls ; ls -ls ls >wc Pipes - standard output to standard input (commands must be compatible) - send standard output of one command to standard input of another - $ date > out ; wc