------------------------- Week 03 Notes for NET2003 ------------------------- -Ian! D. Allen - idallen@idallen.ca - www.idallen.com Remember - knowing how to find out an answer is more important than memorizing the answer. Learn to fish! RTFM! (Read The Fine Manual) Review ------ 1 bash 2 cal (9 1752) 1 cat (-s) 1 cd 1 cp (-u) 1 date 1 dir (DOS alias - use ls instead) 1 echo (shell built-in and external) 2 exit (shell built-in) 2 ifconfig 1 less 1 ls ( -l -a -d ) 1 man (-k) 1 more 2 mv 2 passwd 1 pwd (shell built-in and external) 2 rm ( -r -f ) 2 sort (-n -r -u) 2 stty ( erase '^H' erase '^?' ) 1 vi, vim (-r) 2 wc ( -l -w -c ) 2 wget [-O outfile] {URL} 1 which 1 who Q: What is the output on your screen of "sort foo foo" if foo contains: 2 22 11 1 Q: How do you tell sort to sort by number? sort in reverse? Q: How do you fetch the file at URL http://tc.ca/ into your current directory? VIM Tips -------- - Multi-window multi-file editing: :split, :vsplit, :qall, ^W For help in VIM type :help ^W Linux basics - continued ------------ Unix directory tutorial: - http://www.ee.surrey.ac.uk/Teaching/Unix/unix1.html (but note that they incorrectly give the ROOT directory a name of "/") The Unix Shell (e.g. "bash" - Bourne Again SHell) - Notes: shell_basics.txt - The Unix/Linux Shell - purpose of a shell is: to find and run commands - with some support for programming (scripts) - you can use ";" to separate multiple commands, e.g.: $ sleep 4 ; echo BOO $ date ; date ; date - in shell scripts, avoid using ";" - put each command on its own line - 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 - type "exit" to cause a shell to terminate - 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 - 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 - shell can expand file GLOB patterns (similar to DOS wildcard) - shell helps with wildcards (GLOB) - * matches zero or more characters - ? matches a single character (any character, even a space) - [abc] matches a single character from the list abc - like ls, GLOB patterns never match names that start with a period (hidden pathnames), unless you explicitly put a real period at the start - echo * - does not match hidden files - echo ?* - does not match hidden files - echo [.]* - does not match hidden files - echo .* - matches only hidden files (pattern starts with a real period) - Notes: glob_patterns.txt - GLOB patterns (wildcard pathname matching) - shell can expand variables, both local and environment - e.g. you can see a $variable as in: echo "$SHELL" - the shell does the variable expansion, not the command! Searching for text inside files: $ grep 'pattern' [files...] - crude Data Mining: selecting content by looking for lines - searching for keywords in the course notes: $ grep 'ssh' ~idallen/public_html/teaching/net2003/08w/notes/*.txt - the grep -v option finds lines that do *not* contain the pattern - similar in behaviour to the g// and v// commands in VIM Course Notes to read -------------------- arguments_and_options.txt glob_patterns.txt miscellaneous.txt shell_prompt.txt unix_command_list.txt ============================================================================ Q: What is the main purpose of a shell program? Q: T/F any program that wants to read from your keyboard will prompt you for input Q: T/F the number of extra blanks between arguments on the shell command line doesn't matter - one blank is the same as twenty Q: Describe how GLOB patterns work in the Unix shell. Q: Describe how to stop the shell from splitting text at blanks (e.g. a file name with blanks in it) Q: T/F shell GLOB patterns *never* match leading periods in names Q: T/F "echo [.]*" matches all hidden file names Q: T/F In the command "echo *" it is the "echo" command that expands the "*". Q: T/F In the command "ls *" it is the "ls" command that expands the "*". Q: T/F In the command "echo $SHELL" it is the "echo" command that expands the $SHELL variable Q: What type of pathnames does "echo */." output? Q: What type of pathnames does "echo ./*" output? Q: How do I search for text in a directory full of files?