------------------------ Week 2 Notes for DAT2330 ------------------------ -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 is in Week #5 (see the Course Home Page). - You all were sent email about this test on Sunday January 22. Learning the VIM editor: The intent of the vim tutorial is to teach you how to use the vim editor. If you can't remember what you did in the tutorial, redo it until you remember. Don't print the tutorial; do it. (You already have a very nice printed reference sheet for vim.) You must learn to use this editor; your final exam depends on it. The tutorial can be run under Knoppix anywhere you can run Knoppix. It can be run on the Course Linux Server or on ACADUNIX using remote login via PuTTY. Do it! See week01notes.txt or exercise01.txt for details on running the tutorial. In Week 1 and 2 (see also week01notes.txt) you did this: - you received a guided tour of the course home page - you forwarded your Algonquin email to an account that you read regularly - you received a Knoppix CDROM and know how to boot it (knoppix_booting.txt) - you connected to the ACADUNIX computer and verified that your account works (acadunix_help.txt) - you connected to the Course Linux Server and verified that your account works (Notes: course_linux_server.txt) - you created the ".vimrc" file mentioned in the "Setting VIM Options" section of file vi_basics.txt (on both ACADUNIX and Linux) and you learned some basic VI/VIM commands in the online tutorial - you completed the rest of the online vim tutorial for homework - you know how to set your terminal erase character using the "stty" command (Notes: terminal.txt) - you know how to use the "datsubmit" command to submit a text file for marking (Notes: datsubmit.txt) - you can find the assignment label (see button under teaching.idallen.com) - you were introduced to the Unix password file: /etc/passwd - you learned the basic meanings of the commands in unix_command_list.txt also: ls -l also: sort -n also: grep -v also: man -k also: stty erase '^?' also: stty erase '^H' also: how to get help inside "less" and "more" (and "man") - you can cut-and-paste using the X11 window system mouse - you can open browser "tabs" inside either Firefox, Konqueror, or Mozilla - you know why pathname slashes go forward in web URLs - you can search for text inside the "less" pagination program - you can search for text inside vim - you don't use the arrow keys in vim, you use h,j,k,l - you can find manual pages containing any single keyword - you know how to login remotely to ACADUNIX and the Course Linux Server - you use "hostname" to make sure you are on the right system - you know the meaning of these characters at a shell prompt: ^W ^U ^L TAB - you know the difference between: ^C ^D - you can switch consoles CTRL-ALT-F1, ALT-F2, etc. - you submitted week02lab.txt as Exercise 52 using datsubmit. - you completed these readings in the Class Notes: acadunix_help.txt Using the ACADUNIX IBM Unix machine course_linux_server.txt The Course Linux Server datsubmit.txt Using the datsubmit command file_transfer.txt File transfer between machines internet_basics.html Internet Networking Basics, URLs, etc. knoppix_booting.txt Using the Knoppix Linux CDROM man_page_RTFM.txt Searching for items in the Unix manual pages terminal.txt Using Telnet/Ssh terminal emulators vi_basics.txt The VI (VIM) Editor - Basics vi_refcard_front.pdf, vi_refcard_back.pdf - VIM reference Unix is an O/S designed by programmers for programmers - command-line driven (programmers didn't use the GUI) - things work silently (no confirmation) - messages appear only when things fail - most command names are cryptic abbreviations! - hard to learn but easy to use Entering commands via command lines - the terminal driver - your terminal is two devices (keyboard and screen), loosely coupled - the keys you type all go through Unix before appearing on your screen - programs can choose not to display characters (e.g. passwords) - programs can change what the characters mean (e.g. vim) - many programs can all write to your screen at the same time - the terminal driver intercepts some characters and uses them - in printed documents we use the two-character form ^A to indicate the unprintable control character CTRL-A - when you see ^A it means hold down the CTRL key and type the single letter "a" (upper or lower-case) - some programs let you use this syntax directly, e.g.: stty erase ^H - NOTE: the sequence ^? stands for the ASCII DEL character, not CTRL-? When you see ^? it means use the DEL key, not CTRL-? - default line edit characters: ^H ^? ^U ^W ^R ^L ^H or ^? - backspace and erase one character ^U - erase entire line of typing ^W - erase one word in current line ^R - redraw current line (in case overwritten) ^L - clear/redraw screen (in bash, less, more, and vim) Other special keyboard characters: - these characters operate with most Unix programs; however, some programs (e.g. vim) can change their meaning: ^C - send interrupt signal (SIGINT) to current process The Unix Shell (e.g. "bash" - Bourne Again SHell) - See Notes: shell_basics.txt - The Unix/Linux Shell - purpose: to find and run commands - with some support for programming (scripts) - GLOB patterns, aliases, variables, history, name completion - shell is an unprivileged program - standard Linux shell is named "bash"; you can start up multiple copies of bash by typing its name as a command: bash - shell prompts when it reads from your keyboard - shell does not prompt if reading input from a file! - most other Unix programs do *not* prompt when they read your keyboard - See Notes: shell_prompt.txt - Setting the BASH shell prompt - shell splits your command line on blanks (white space) - first non-redirection word is the command name - the rest of the arguments are passed to the command - Notes: arguments_and_options.txt - Options and Arguments on Command Lines - you can use a semicolon (";") to separate commands: $ sleep 4 ; echo BOO $ date ; who ; echo hi ; wc /etc/passwd - commands are executed left-to-right, even if a command fails $ nosuchcommand ; echo this works Listing files - ls - long listing: ls -l /etc/passwd -rw-r--r-- 1 root root 2871 Aug 24 02:14 /etc/passwd * first character indicates type of pathname: file, directory, etc. * next nine characters rw-r--r-- are three sets of permissions * next number 1 is the count of names this pathname has (Unix/Linux files can have multiple names) * next string root is the owner of this file * next string root is the group of this file * next number 2871 is the size of the file in bytes (including all characters, including spaces and newlines) * next comes the modify date and time of the file (Unix does not keep the creation time of any file) * last is the name Pagination commands - less and more - one small set of commands does all the pagination - pagination is not built in to each command, as in DOS - searching can be done using / in programs "more" and "less" (and vim) Man pages (and the "info" command): - know how to use the man command, man -k, and apropos - apropos == man -k - See Notes: man_page_RTFM.txt - man pages come in different sections: man 1 passwd ; man 5 passwd - know how to read man pages (man page syntax meaning) - 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 Keep a List of Unix Commands: - 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 -a -l") - keep current on the commands covered; look up what you don't know Line Ends Lines end in newline ("\n", NL, LF) characters on Unix. On Microsoft systems, they end in carriage-return ("\r", CR) followed by newline: CR/LF. On Macintosh systems, they end in carriage-return characters only. When counting the characters in a Unix 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".