------------------------ Week 3 Notes for DAT2330 ------------------------ -Ian! D. Allen - idallen@idallen.ca Remember - knowing how to find out an answer is more important than memorizing the answer. Learn to fish! RTFM! (Read The Fine Manual) ------ Review ------ In Week 2 (week02notes.txt) you finished learning VI/VIM basics from Running Linux Chapter 9, the online vim tutorial, and the vi_basics.txt file. You created a .vimrc file and perhaps printed a "VI cheat sheet". You did these readings in Running Linux, Chapter 4: "Intro", "Logging In", "Setting a Password", "Virtual Consoles" p.81-84 "Directories", "Listing Files" p.84-86 "Viewing Files" p.86-87 "Shells" p.88-89 "Useful Keys" p.90 "Typing Shortcuts", "Word Completion" p.91 "Moving Around Among Commands" p.92 "Filename Expansion" p.92-93 "Saving Your Output", "What is a Command" p.93-97 "Manual Pages" p.98-100 You did these readings in Using Unix: Chapter 1 - all Chapter 3 - all but omit "Changing Group and Owner" Chapter 4 - File Management - omit Pico - omit "Finding Files" - omit "Files on other operating systems" - omit "Printing Files" - make sure you can do the exercise on p.96 (omit the printing step) Chapter 5 - Redirecting I/O (all) You read these files under the Notes button on the course home page: acadunix.help Using the ACADUNIX computer arguments_and_options.txt Command line arguments and options course_linux_server.txt Using the Course Linux Server computer dat2330_04w_course_outline.pdf Course Outline home_and_HOME.txt Directories: current, HOME, and /home internet_basics.html Internet Networking Basics, URLs, etc. knoppix_booting.txt Using the Knoppix CDROM man_page_RTFM.txt Searching for items in the Unix manual pages (RTFM) miscellaneous.txt Miscellanous Unix Facts pathnames.txt Unix/Linux Pathnames quotes.txt Unix/Linux Shell Command Line Quoting redirection.txt Redirecting the I/O of commands shells.txt The Unix Shell telnet_usage.html Using Telnet/Ssh to Unix Systems vi_basics.txt The Basics of using the VIM editor You finished DAT2330 Exercise #1. You added these commands to your list of known Unix commands: cal cd cp du exit file head pwd tail touch vi vim sort(-r) cat rm(-r) mkdir rmdir mv find ------------------ This Week (Week 3) ------------------ 1. Finish the VIM tutorial! I mean it! 2. New commands/options in the labs this week: apropos sum last sleep hostname head(-5) tail(-5) 3. searching with / in MORE and LESS 4. Getting out of programs (see miscellaneous.txt) 5. Exterior assignment label (see button under teaching.idallen.com) 6. Redirection: see Notes file redirection.txt - input redirection, and output redirection into files and programs 7. /dev/null 8. Pipes: see Notes file redirection.txt 9. Lines end in newline ("\n", NL) characters on Unix. On Microsoft systems, they end in carriage-return ("\r", CR) followed by newline. On Macintosh systems, they end in carriage-return characters. When counting the characters in a file, remember to count the newlines: The line "hi", when stored in a Unix file, occupies 3 characters. The output of "echo hi | wc -c" is "3". 10. Exercise 53: submit the top five lines of the sorted passwd file 11. Hidden files as (not) seen by ls and glob wildcard * - GLOB patterns do not match hidden files unless you explicitly include the leading period: echo .* 12. Redirection into a file in another directory: $ mkdir foo ; ls -l >foo/bar $ date >/tmp/myfile 13. New commands/options in the lecture this week: passwd tr diff cut awk($1) uniq wc(-lwc) ls(-sd) sort(-nr) grep(-v) - the tr command never takes pathnames (only reads stdin) - the ls command never reads stdin (always lists some directory) - Warning! the second argument to the uniq command is an (optional) OUTPUT file name! Be careful! Some examples used in class: $ tr '[a-z]' '[A-Z]' out ; echo b >>out ; wc -c out - why 4 chars? Use either "cut" or "awk" to select a field in input lines: - "cut" treats every delimiter as starting a new field - "awk" treats spans of whitespace as starting new fields $ echo "a b c" | cut -d ' ' -f 2 # does not print "b"! $ echo "a b c" | awk '{print $2}' # does print "b" $ date | cut -d ':' -f 2 $ last | awk '{print $1}' | sort | uniq -c | sort -nr | head $ last | awk '{print $1}' | sort | uniq -c | grep ' 1 ' | wc -l 14. Know the difference between command names, options, and file names: $ echo a b c >out ; >out echo a b c $ date >wc ; >wc date ; wc -wc wc >ls ; ls -ls ls >wc 15. Man pages (and the "info" command): * RL "Manual Pages" p.98 * LU "Manual Pages" p.136 - apropos == man -k - see Notes file man_page_RTFM.txt - some Unix command "man" pages refer you to the "info" pages (e.g. "sort"). Try the "pinfo" command for easier access to "info" style pages, e.g.: $ pinfo sort 16. Usenet news - how to read the course announcements and discussion group - see button News&Discussion on the course home page - post questions to the Discussion news group - practice posting and cancelling in the algonquinc.test news group (under News&Discussion) using the NNTP interface 17. Readings in Running Linux: "Moving Around Among Commands" p.92 (Note: to enable vi-mode in bash, use: set -o vi but be aware that ^L will stop working if you do) "Filename Expansion" p.92 "What is a Command" p.96 [assigned last week] "Putting a Command in the Background" p.98 "Manual Pages" p.98 "Startup Files" p.106 "Important Directories" p. 108 18. Readings in Learning Unix: Same as last week (emphasis on glob wildcards), plus: "Manual Pages" p.136 19. Readings in the online course Notes files: practiceTest1.* Practice questions for Week 5 midterm test practiceCommands_1.txt Practice problems file_system.txt Unix/Linux File System - (correct explanation) links_and_inodes.html Hard links and Unix file system nodes (inodes) stdxxx.c++.txt C++ program using stdout, stderr, stdin. 20. Study the examples in the Practice Tests. There is only one version of the practice test; but, all three formats have the same questions in a different random order. The answer key for each test is at the end of each practice test. The Practice Commands file is a set of questions and exercises of varying difficulty. You should know how to do most of these questions based on the Lectures and readings. 21. Exercise #2 - due Tuesday February 3.