% CST8207 Week 03 Notes -- absolute and relative paths, ROOT and HOME, finding files, file GLOB patterns % Ian! D. Allen -- -- [www.idallen.com] % Fall 2016 - September to December 2016 - Updated 2017-01-20 00:48 EST - [Course Home Page] - [Course Outline] - [All Weeks] - [Plain Text] Readings, Assignments, Labs, Tests, and ToDo ============================================ Read (at least) these things (All The Words) -------------------------------------------- 1. [Week 03 Notes HTML] -- this file -- **Read All The Words** 2. [File System and Pathnames] -- ROOT, absolute, relative, dot, dot dot 3. [Directories: ROOT, /root, HOME, /home, and current] 4. [Searching for and finding files by name, size, use, modify time, etc.] 5. [Shell GLOB patterns (wildcard pathname matching)] 6. [List of Commands You Should Know] 7. [Linux and Sysadmin News in the World] - Create your [lynda.com] account and watch these sections of [Unix for Mac OS X Users] - these videos are for *all* Unix/Linux students, not just Mac OSX users - **3. Working with Files and Directories** - Naming files 5m 41s - Unix is case-sensitive, OSX is case-insensitive! - avoid special characters or blanks in Unix pathnames - Creating files 2m 19s - `touch` - Unix text editors 6m 39s - `vi/vim, nano` - `head, tail` - Reading files 5m 35s - `cat, more, less` - Reading portions of files 3m 27s - `head, tail` - Creating directories 2m 40s - `mkdir` - Moving and renaming files and directories 8m 32s - `mv` (including using `..`) - Copying files and directories 3m 7s - `cp` - Deleting files and directories 3m 38s - `rm, rmdir` - Searching for files and directories 6m 32s - `find` using "wildcard" (GLOB) patterns - same as shell GLOB - **5. Commands and Programs** - Command basics 4m 4s - commands are usually small programs; ways to exit from programs - Using the command history 8m 16s - shell command history is saved your `.bash_history` file Assignments this week --------------------- Check the due date for each assignment and put a reminder in your agenda, calendar, and digital assistant. - Review last week. Did you do everything assigned last week? - Read All The Words, Do, and then Submit via Blackboard: - [Assignment #03 HTML] -- working with files: `PS1 find mkdir mv cp` - Coming Soon: Bonus (optional) [Assignment #04 HTML] -- the VIM text editor - Assignment #05 HTML will be out soon -- using GLOB patterns and redirection - Really do **Read All The Words**. You don't get a second chance to get it right. Lab work this week ------------------ - Read [File System and Pathnames] and then finish work on [Worksheet #02 PDF] and [Worksheet #03 PDF] so you can do [Assignment #03 HTML]. - Read [The VI (VIM) Text Editor] and optionally do the bonus [Assignment #04 HTML]. - For upcoming Assignment 5 do [Worksheet #04 PDF] -- shell GLOB patterns and Aliases ### Worksheets Worksheets are preparation for your assignments. You can't do the assignments without having done the worksheets first, and you can't do the worksheets without having first read the Course Notes: 1. Read. 2. Worksheet. 3. Assignment. Form a small study group to do the worksheets. Each person tries the example given, and you make sure you all get the same answers. Worksheets are not for hand-in; they are not worth marks; the assignments test your knowledge of the lectures and worksheets. > The worksheets are available in four formats: Open Office (ODT), PDF, HTML, > and Text. Only the Open Office format allows you "fill in the blanks" in > the worksheet. The PDF format looks good but doesn't allow you to type into > the blanks in the worksheet. The HTML format is crude but useful for quick > for viewing online. Do **NOT** open the Worksheet ODT files using any Microsoft products; they will mangle the format and mis-number the questions. Use the free Libre Office or Open Office programs to open these ODT documents. On campus, you can [download Libre Office here]. These first two worksheets require you to have read [File System and Pathnames]: - [Worksheet #02 ODT] -- Using standard Linux commands I - [Worksheet #02 PDF] - [Worksheet #02 HTML] - `PS1, cd, find, less, ls, man, mkdir, passwd, pwd, rmdir` - [Worksheet #03 ODT] -- Using standard Linux commands II - [Worksheet #03 PDF] - [Worksheet #03 HTML] - `cat, clear, cp, find, grep, history, less, man, mv, rm, sleep, touch` - [Worksheet #04 ODT] -- shell GLOB patterns and Aliases - [Worksheet #04 PDF] - [Worksheet #04 HTML] - shell GLOB patterns (wildcards), Aliases: `alias, sum, unalias` - [Worksheet #06 HTML] -- *Optional* Bonus VIM Text Editor Practice - This is an *optional* worksheet for a BONUS assignment using `vim` - Optional command-line VIM tutorial: the `vimtutor` program on the CLS. - Bonus (optional) [Assignment #04 HTML] -- the VIM text editor - Read [The VI (VIM) Text Editor] Worksheets prepare you for the upcoming assignments. Notes from the Classroom ======================== - **Take notes in class!** Keep a pad open on your desk. - This week, we finish with using pathnames and learn how to find files and match file names with GLOB patterns. ![An Update Is Available] Did not change password -- CLS access revoked --------------------------------------------- Students will have their CLS accounts disabled if they have not changed their default password. (I do not want people breaking into my machine because of you.) See my online timetable for how to make an office appointment to see me if you want your account back. Fifteen minute rule ------------------- Your time as a student is valuable. If you come up against a tough problem and make no progress in fifteen minutes despite best efforts: 1. get help from a professor or lab instructor 2. get help from classmates 3. take a break 4. put it on hold and work on something else This happens to all of us, and we need to watch out for it when it happens. *But what about when it's midnight before the assignment is due?* Remember the "Don't Leave Things to the Last Minute" rule! Drawing File System Diagrams ---------------------------- See the note in [Assignment #03 HTML] about drawing file system diagrams on paper. Do it. Commands Used ------------- Keep a notebook with a [List of Commands][List of Commands You Should Know] in it. - You need to write down yourself what each command *does*. - I will check for this list in your lab periods. - Check the updated list of commands each week. - You can tell whether a file system name is a directory or a file by looking for a letter `d` on the left in the output of `ls -l`. Ordinary files are indicated by a dash `-` character on the left. The first two lines, below, are files. The last three are directories. $ ls -l / -rw-r--r-- 1 root root 22528 Sep 4 11:01 aquota.group -rw-r--r-- 1 root root 73728 Sep 4 11:01 aquota.user drwxr-xr-x 2 root root 4096 Jul 1 15:57 bin drwxr-xr-x 3 root root 4096 Sep 2 17:58 boot drwxr-xr-x 2 root root 4096 Sep 7 2012 cdrom - The `rmdir` command will only remove an empty directory. - You know this from doing Section 5 of [Worksheet #02 HTML]. - How do you remove a directory *and* everything inside it? (You know the answer from doing the Worksheets, especially Section 5 of [Worksheet #03 HTML].) - The copy command `cp` will not copy directories unless you use the right option. (You know this option from doing Section 3 of [Worksheet #03 HTML].) - The copy command `cp` and rename/move command `mv` can both accept a directory as the destination, and will put all the source files into that destination directory using the source file name(s): - If `bar` is a directory, then `cp foo bar` creates file `bar/foo` - If `bar` is a directory, then `mv foo bar` creates file `bar/foo` - If `bar` is *not* a directory, then `cp foo bar` creates file `bar` - If `bar` is *not* a directory, then `mv foo bar` creates file `bar` - You can use pathnames anywhere you can use a file name, even for output redirection, e.g.: $ date >date.txt # date.txt in the current directory $ date >../date.txt # date.txt in the parent directory $ mkdir foo $ date >foo/date.txt # date.txt in the foo directory $ mkdir foo/bar $ date >foo/bar/date.txt # date.txt in the foo/bar directory You will need to know this for [Assignment #03 HTML]. Attacks on the CLS ================== Commands to show the number of locked out IP addresses and attempts to use locked-out IP addresses in `/etc/hosts.evil`: $ wc /etc/hosts.evil $ fgrep -c 'refused' /var/log/auth.log $ fgrep 'refused' /var/log/auth.log | less Count the unique locked-out addresses and show the top twenty: $ fgrep 'refused' /var/log/auth.log | awk '{print $NF}' | sort -u | wc $ fgrep 'refused' /var/log/auth.log | awk '{print $NF}' | sort | uniq -c | sort -nr | head -n 20 Password failures: $ fgrep -c 'Failed' /var/log/auth.log $ fgrep 'Failed' /var/log/auth.log | less Userid failures: $ fgrep -c 'input_userauth' /var/log/auth.log $ fgrep 'input_userauth' /var/log/auth.log | less You can use the `whois` command on Linux to identify which country is responsible for an IP address, or use a [Web Whois Lookup]. (The Linux `whois` command is blocked from use at Algonquin College, except if you are on the CLS. You can't use the Linux command in your own Linux machines on campus. Use it on the CLS or use the web interface instead.) Locked out of the CLS ===================== When you are locked out, [follow the directions] in the notes to get your IP address re-enabled. ![Take Notes in Class] -- | Ian! D. Allen, BA, MMath - idallen@idallen.ca - Ottawa, Ontario, Canada | Home Page: http://idallen.com/ Contact Improv: http://contactimprov.ca/ | College professor (Free/Libre GNU+Linux) at: http://teaching.idallen.com/ | Defend digital freedom: http://eff.org/ and have fun: http://fools.ca/ [Plain Text] - plain text version of this page in [Pandoc Markdown] format [www.idallen.com]: http://www.idallen.com/ [Course Home Page]: .. [Course Outline]: course_outline.pdf [All Weeks]: indexcgi.cgi [Plain Text]: week03notes.txt [Week 03 Notes HTML]: week03notes.html [File System and Pathnames]: 160_pathnames.html [Directories: ROOT, /root, HOME, /home, and current]: 170_home_and_HOME.html [Searching for and finding files by name, size, use, modify time, etc.]: 180_finding_files.html [Shell GLOB patterns (wildcard pathname matching)]: 190_glob_patterns.html [List of Commands You Should Know]: 900_unix_command_list.html [Linux and Sysadmin News in the World]: 950_linux_world.html [lynda.com]: http://algonquincollege.com/onlineresources/mobileStudent/lynda.htm [Unix for Mac OS X Users]: http://www.lynda.com/Mac-OS-X-10-6-tutorials/Unix-for-Mac-OS-X-Users/78546-2.html [Assignment #03 HTML]: assignment03.html [Assignment #04 HTML]: assignment04.html [Worksheet #02 PDF]: worksheet02.pdf [Worksheet #03 PDF]: worksheet03.pdf [The VI (VIM) Text Editor]: 300_vi_text_editor.html [Worksheet #04 PDF]: worksheet04.pdf [download Libre Office here]: 050_course_introduction.html#install-libreoffice-or-openoffice-into-windows [Worksheet #02 ODT]: worksheet02.odt [Worksheet #02 HTML]: worksheet02.html [Worksheet #03 ODT]: worksheet03.odt [Worksheet #03 HTML]: worksheet03.html [Worksheet #04 ODT]: worksheet04.odt [Worksheet #04 HTML]: worksheet04.html [Worksheet #06 HTML]: worksheet06.html [An Update Is Available]: data/update_available.jpg "An Update Is Available" [Web Whois Lookup]: http://whois.domaintools.com/ [follow the directions]: 070_course_linux_server.html#getting-locked-out-of-the-server [Take Notes in Class]: data/remember.jpg "Take Notes in Class" [Pandoc Markdown]: http://johnmacfarlane.net/pandoc/