------------------------ Week 4 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). - practice questions and practice test is available under Notes - one crib sheet, letter or A4, one side - termtest1directions.txt Directions and preparing for Test #1 - practiceCommands_1.txt Practice Unix/Linux Questions #1 - practiceTest1.* Practice Test #1 Questions Review: ^C ^D, echo hi | wc wc -wc wc >wc ; ls -ls wc >date x='*' ; echo $x ; echo "$x" OUTPUT: "You can only redirect what you can see." INPUT: "The shell can't force a program to read stdin." "Programs that read files, when run without file names, read stdin." WRONG: echo /bin | ls, cp foo bar >out, sort f See Notes file miscellaneous.txt Why doesn't backspace always work? - command: stty erase ^? - command: stty erase ^H - learn various ways of getting out of programs - don't send binary (executable machine code) files to your screen - check the contents with the "file" command first Man pages (see Notes man_page_RTFM.txt): - know how to read man pages (man page syntax meaning) New commands: tree, sum, cat -n, last, diff -u, stty, cut -d -f, uniq -c - See Notes: unix_command_list.txt - keep an ongoing list of commands and their common uses - keep notes on what the common options do (e.g. "ls -alsd") - keep current on the commands covered; look up what you don't know - "ls -ld" is needed to see the attributes of a directory (instead of seeing the attributes of the directory contents) - note that "ls" really means "ls ." - note that "ls -d" really means "ls -d ." - ls -s shows sizes in blocks (usually 1K blocks on Linux) - cut selects fields from input lines - head,tail,grep select lines, cut selects "columns" - combined, you can select anything from a text file by row and column Building command pipelines: Find the userid that logs in the most? Build up a command pipeline slowly, from individual parts: $ last $ last | cut -d ' ' -f 1 $ last | cut -d ' ' -f 1 | sort $ last | cut -d ' ' -f 1 | sort | uniq -c $ last | cut -d ' ' -f 1 | sort | uniq -c | sort -nr $ last | cut -d ' ' -f 1 | sort | uniq -c | sort -nr | head -1 Redirect stderr separate from stdin (see Notes redirection.txt): 1>out vs. 2>out, 2>&1 "send stderr to same place as current stdout" ls . nosuch 2>&1 >out # WRONG ls . nosuch >out 2>&1 Throw away unwanted output to /dev/null $ ls . nosuch 2>/dev/null $ cat /etc/* 2>/dev/null >out Redirect stdin from file, not program (see Notes redirection.txt): wc