------------------------ Week 6 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 5 (week05notes.txt) you studied for your first term test. You know how to have a shell read commands from a file instead of stdin. You can make a text file into an executable shell script. You know how #!/bin/sh works, and what program processes this line. You know what $PATH is and its relation to "which" and "whereis". You can create/list/extract a "tar" archive, either compressed or not. Lab Exercise: - create a subdirectory and in it create a sub-subdirectory - copy in Unix password file; create a few other files - now use "tar" to copy this directory to a new directory: - save the current directory into "out" in the parent directory (WARNING: Never have tar reading its output file as an input file!) - show a table of contents - make a new directory in the parent and change into it - extract the tar file into the current directory $ tar czvf ../out . $ file ../out $ tar tzvf ../out $ mkdir ../new $ cd ../new $ tar xzvf ../out $ ls -l ------------------ This Week (Week 6) ------------------ Your first Midterm Test is in your lecture period on Friday, February 13. * Compression Utilities - gzip and bzip2 - Running Linux: "Archive and Compression Utilities" p.175 - Running Linux: "Using gzip and bzip2" p.175 - Running Linux: "Using tar with gzip and bzip2" p.183 Run "whereis bash" and note the location of the .bz2 manual page. Copy this file into your current directory and uncompress it. $ whereis bash $ cp /usr/man/man1/bash.1.bz2 . $ file bash.1.bz2 $ bunzip2 bash.1.bz2 $ file bash.1 $ less bash.1 bzip2 provides better compression than the older gzip utility. A compressed tar file is just an uncompressed tar file that has been post-processed with either gzip or bzip2. The "z" option to tar is just a convenient way to run gzip on the tar archive without having to type the gzip command yourself. * File and Directory Permissions Read: - Running Linux: "File Ownership and Permissions" p. 100 - Running Linux: "What Permissions Mean" p.101 - Running Linux: "Owners and Groups" p.101 - Running Linux: "Changing the Owner, Group, and Permissions" p.103 - ignore chown and chgrp; learn how to use chmod - Notes: unix_permissions.txt - understanding Unix permissions - Notes: umask.txt - Umask and Permissions "r" permission on a directory means you can only see the names, not use them "x" permission on a directory means you can only use the names, not see them New commands: chmod umask Syntax: chmod [ugoa][-+=][rwx] pathnames... How can you create a file that you yourself cannot read, but that everyone else can read? (chmod 044 file or chmod u=,go=r file) * Lab Exercise (similar to next upcoming exercise): We decoded the tar file from last term's Exercise #6 (from Fall 2003) and displayed it on our Knoppix screens ("xli tux.jpg"). Exercise #3 this term will be similar to that exercise from last term. * Executing commands when you log in: Startup Files - Running Linux: "Startup Files" p.106 Use .bash_profile for commands that need to be done *once* at login - e.g. to set PATH, umask, prompt (PS1), and erase character Use .bashrc for commands that need to be done for *every* bash shell - e.g. to set bash aliases Read: shell_prompt.txt - Setting the BASH shell prompt * Manual Page Syntax You need to know what the [] and {} and "..." mean in the syntax section of Unix manual pages, so that you can write your own Syntax when you create shell scripts. [ foo ] - something "foo" is optional { a | b | c } - select any one of the list a or b or c file... - one or more files If you are told to refer to an "info" page, try the "pinfo" command instead (easier to use). "info" pages are awkward to navigate. You often need to use "grep" to help you find relevant man pages: man_page_RTFM.txt Searching for items in the Unix manual pages (RTFM) * Foreground / Background - Running Linux: "Putting a Command in the Background" p.98 - Learning Unix: Chapter 7 - Multitasking - only one process can read your keyboard at a time; this process is considered to be "in the foreground" - you can start up "background" processes if they don't need your keyboard $ sleep 123 & - if a background process tries to read your keyboard, it will be stopped by the Unix kernel (not killed; just stopped) - you can kill it or make it a foreground process (give it the keyboard) - ^Z stops a process (it still exists but uses no CPU time) - "bg" puts a stopped process into running in the background - "fg" puts a stopped or background process into running in the foreground - "kill" terminates a process - you can always use numeric PIDs to kill - you can only use % job identifiers if the job belongs to the current shell - "jobs" lists jobs belonging to the current shell only - "ps" lists all your processes, everywhere New commands: ^Z fg bg jobs ps kill