% CST8207 Week 04 Notes – finding files, GLOB wildcards, I/O redirection % Ian! D. Allen – – [www.idallen.com] % Winter 2015 - January to Apil 2015 - Updated Thu Jan 29 03:17:04 EST 2015 Readings, Assignments, Labs, Tests, and ToDo ============================================ - Read (at least) these things (All The Words): 1. [Week 04 Notes HTML] – this file – **Read All The Words** 2. [Searching for and finding files by name, size, use, modify time, etc.] 3. [Shell GLOB patterns (wildcard pathname matching)] 4. [Unix Shell I/O Redirection (including Pipes)] 5. [List of Commands You Should Know] 6. [Video Tutorials on Lynda.com] - Create your [lynda.com] account and watch [Unix for Mac OS X Users] - **3. Working with Files and Directories** - Unix text editors 6m 39s - `vi/vim, nano` - `head, tail` - Searching for files and directories 6m 32s - `find` using “wildcard” (GLOB) patterns - same as shell GLOB - **6. Directing Input and Output 20m 39s** - Standard input and standard output 1m 24s - Directing output to a file 4m 13s - Appending to a file 2m 44s - Directing input from a file 5m 28s - Piping output to input 4m 40s - Suppressing output 2m 10s - **7. Configuring Your Working Environment 41m 28s** - Setting command aliases 6m 59s - saving aliases in your `.bashrc` file Assignments this week --------------------- Check the due date for each assignment and put a reminder in your agenda, calendar, and digital assistant. - Read All The Words, Do, and then Submit via Blackboard: - [Assignment #03 HTML] – working with files: `PS1, find, mkdir, mv` - Bonus (optional) [Assignment #04 HTML] – the VIM text editor - [Assignment #05 HTML] – using GLOB patterns and redirection - Really do **Read All The Words**. You don’t get a second chance to get it right. ### 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 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]. - [Worksheet #04 ODT] – shell GLOB patterns and Aliases - [Worksheet #04 PDF] - [Worksheet #04 HTML] - shell GLOB patterns (wildcards), Aliases: `alias, sum, unalias` - [Worksheet #05 ODT] – shell I/O redirection (including pipes) - [Worksheet #05 PDF] - [Worksheet #05 HTML] - shell I/O redirection, `date, head, nl, tail, tr, wc` - [Worksheet #06 ODT] – *Optional* Bonus VIM Text Editor Practice - [Worksheet #06 PDF] - [Worksheet #06 HTML] - This is an *optional* worksheet for a BONUS assignment using `vim` - Optional command-line VIM tutorial: the `vimtutor` program on the CLS. - Optional Reading: [The VI (VIM) Text Editor] - Bonus (optional) [Assignment #04 HTML] – the VIM text editor Lab work this week ------------------ - [Assignment #03 HTML] is ready - Bonus (optional) [Assignment #04 HTML] is ready - Finish the above assignments, which involve work on the first two worksheets. Upcoming tests -------------- Read the [Test Instructions] (all the words) before your first midterm test. 1. First Midterm test: 45 minutes; in class 8am Thursday in Week 6 (February 12) 2. Second Midterm test: 45 minutes; in class 8am Thursday in Week 9 (March 12) Tests take place in your 8am lecture hour, not in your lab period. ### Midterm Test #1 - Midterm #1 takes place 8am Thursday February 12 (Week 6) in your scheduled lecture hour (not in your lab period). - For full marks, you must read the [Test Instructions] before the test for important directions on how to enter your answers, your lab (not lecture) section number, and the test version number on the question sheet and the mark-sense forms. - There may be more questions on the test than you can answer in the time allowed; answer the ones you know, first. - I will post a set of practice questions and quizzes for the test soon. From the Class Notes link on the Course Home Page ================================================= - Review last week. Did you do everything assigned last week? From the Classroom Whiteboard/Chalkboard ======================================== - **Take notes in class!** Your in-class notes would go here. - [Do your class notes look like this?] - This week, we learn about pathname GLOB (wildcard) patterns. - Are you making notes from the worksheets on how each command works? - What do the options used in the worksheets mean, for each command? - Don’t copy and use options that you don’t understand! Commands -------- - 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].) Useful commands: - `head, tail, fgrep, wc` - Count the pathnames (5 lines on the CLS): - `ls /bin/*sh | wc` - Count the number of lines containing `idallen` (83 lines on the CLS): - `fgrep 'idallen' /etc/passwd | wc` - More efficient way to count matching lines: - `fgrep -c 'idallen' /etc/passwd` - Show only the last 10 matching lines: - `fgrep 'refused connect' /var/log/auth.log | tail` - `fgrep 'password' /var/log/auth.log | tail` - `fgrep 'idallen' /etc/passwd | tail` - Show your 10 most recent login sessions to the CLS (use your own userid): - `last abcd0001 | head` Real Sysadmin Work ================== Attacks on the Course Linux Server ---------------------------------- - Count the attacks: `fgrep -c "refused connect" /var/log/auth.log` - Another way to count the lines (less efficient): `fgrep "refused connect" /var/log/auth.log | wc` - Only show the last 10 lines: `fgrep 'refused connect' /var/log/auth.log | tail` - See the current list of *evil* host IPs: `less /etc/hosts.evil` * * * * * ![Take Notes in Class] -- | Ian! D. Allen - 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/ [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 [Unix Shell I/O Redirection (including Pipes)]: 200_redirection.html [List of Commands You Should Know]: 900_unix_command_list.html [Video Tutorials on Lynda.com]: 910_lynda_index.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 [download Libre Office here]: 050_course_introduction.html#install-libreoffice-or-openoffice-into-windows [The VI (VIM) Text Editor]: 300_vi_text_editor.html [Test Instructions]: 000_test_instructions.html [Do your class notes look like this?]: data/kf_link_redirect.png [Take Notes in Class]: data/remember.jpg "Take Notes in Class" [Plain Text]: week04notes.txt [Pandoc Markdown]: http://johnmacfarlane.net/pandoc/