------------------------ Week 4 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 3 (week03notes.txt) you added these commands/options to your list of known Unix commands (see Notes file unix_command_list.txt): apropos sum last sleep hostname head(-5) tail(-5) passwd tr diff cut awk($1) uniq wc(-lwc) ls(-sd) sort(-rn) grep(-v) You can search using / in MORE and LESS. You know many ways of getting out of programs. You can create a valid Assignment Label. You understand shell redirection, pipes, and /dev/null. You know about Unix line-end characters in text files. You can translate any set of characters to any other set. You can compare two text files. You can use arguments to head and tail to select any range of lines. You can select fields from input lines (know two commands to do this). You did readings in Learning Unix and Running Linux. You read selected files under the course Notes button. ------------------ This Week (Week 4) ------------------ 1. Understand Unix redirection into files and into programs, including stdin, stdout, and stderr: - all these: > >> < | 1> 2> 2>&1 - Running Linux: "Saving Your Output" p.93 - Learning Unix: Chapter 5 - Redirecting I/O (all) - file redirection.txt under Notes 2. Understand Unix GLOB patterns: * ? [] - Running Linux: "Filename Expansion" p.92 - Learning Unix: Chapter 4 - File Management (Wildcards p.67) $ echo * - no hidden files $ echo ?* - no hidden files $ echo [.]* - no hidden files (this pattern never matches anything) $ echo .* - only hidden files (including . and .. ) $ echo /*/passwd - all directories under ROOT containing passwd $ echo /*/*/passwd - down exactly two levels (not just one) 3. A partial list of special shell meta-characters you know: # $ * | \ [] ; " ' <> ? (There are even more special characters that you don't know yet.) All the above are interpreted by the shell unless they are quoted. Quoting is used to hide metacharacters (including blanks) from the shell: echo 'hello # $ * | \ [] ; " <> ?' "'" 4. You can put multiple commands on one line by separating them with the semi-colon shell metacharacter: date ; who ; ls ; pwd Every command is separate; redirection applies only to a single command, not to the whole line. (To redirect the whole line, put parentheses around it and put the redirection outside.) 5. You can write a simple executable shell script, using a first line of: #!/bin/bash -u and then: $ chmod +x myscript.sh and then: $ ./myscript.sh You can choose a different shell or program by changing the first line. The Unix kernel reads this first line to know which program to use to execute your script. The first line is a comment (ignored) when read by any of the shells. 6. You know about the argv.sh script that prints its arguments: $ ./argv.sh one "two three" four Argument 0 is [./argv.sh] Argument 1 is [one] Argument 2 is [two three] Argument 3 is [four] 7. You heard about inodes and hard-linked file names: links_and_inodes.html Hard links and Unix file system nodes (inodes) file_system.txt Unix/Linux File System - (correct explanation) Examples (most done in class): $ touch a ; ln a b $ ls -il a b $ touch a ; ls -il a b $ chmod +x a ; ls -il a b $ date >a ; ls -il a b ; cat b $ wc a >b - tricky! - never use same input file for output! 8. You learned of the "script" command that will record a terminal session for you: $ script Script started, file is typescript $ ... execute many commands here ... $ exit Script done, file is typescript $ less typescript 9. Start work on DAT2330 Exercise #2. Submit it by the due date. 10. Study for the Midterm Test Friday, February 6: Midterm Topics -------------- * Running Linux: "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 "Saving Your Output" p.93 * Learning Unix: Chapter 1 - Getting Started Chapter 3 - Using your Unix account Chapter 4 - File Management Chapter 5 - Redirecting I/O * Notes: pathnames.txt Unix/Linux Pathnames redirection.txt Unix Shell I/O Redirection miscellaneous.txt Miscellanous Unix Facts internet_basics.html Internet Networking Basics, URLs, etc. home_and_HOME.txt Directories: current, HOME, and /home arguments_and_options.txt Options and Arguments on Unix Command Lines quotes.txt Unix/Linux Shell Command Line Quoting shells.txt The Unix Shell man_page_RTFM.txt Searching for items in the manual pages (RTFM) 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. * Practice: practiceTest1.* Practice Test (PDF, PS, and TXT format) practiceCommands_1.txt Practice commands I will not be asking questions about how to use the VIM editor on this test.