Lecture 2 – Sep 8th, 2022
Setup
Log on to clyde: ssh user@clyde.cs.oberlin.edu.
Task
- Create a directory named
booksusingmkdir. cdinto the directory.wgetto download a copy of Bram Stoker’s Dracula fromhttps://www.gutenberg.org/cache/epub/345/pg345.txt. (Try running either$ wget --helpor$ man wgetto see how to usewgetto download files.- Using
mvrename the file frompg345.txttoStoker, Bram - Dracula.txt. Since this file name has spaces, you’ll need to specify it as'Stoker, Bram - Dracula.txt'orStoker,\ Bram\ -\ Dracula.txt. -
The
grepcommand is used for searching for text files for a “pattern” and printing out each line that matches the pattern. For example,$ grep vampire 'Stoker, Bram - Dracula.txt'prints out each line containing the wordvampire(in lower case).Read
grep’s man page to figure out how to perform a case-insensitive search and run the command to print out all lines matchingvampire, case insensitively. Hint: typing/case(and then hit enter) while viewing a man page will search forcasein the manual. While searching, you can pressn/Nto go to the next/previous instance. - Use
grepto print out a count of the lines matchingvampirecase insensitively. (Search the man page again.) -
You’re probably tired of typing the same command and file name over and over, try using the up/down arrows to move back and forth through the history of your commands and then editing the commands to make new ones. You can also use tab-completion to get Bash to fill in the rest of the name for you: start typing the file name and then hit tab.
Open the man page for
grepone final time and figure out how to getgrepto print the line numbers (and the lines themselves) that matchTransylvaniaand then do that. - Use
wgetagain to download James Joyce’s Dubliners fromhttps://www.gutenberg.org/files/2814/2814-0.txt. Rename itJoyce, James - Dubliners.txt. -
Find and use the command to print out a count of every word in both books. Hint, the
-a(or--and) option toaproposlets you search for commands that involve all of the key words so$ apropos -a apple saucewill match commands whose descriptions contain both the words apple and sauce. So useappropos -awith appropriate keywords to find a command that produces a word count.Run that command on all
.txtfiles in the current directory using$ cmd *.txtwhere
cmdis the command you found withapropos.This is called a glob and we’ll talk about it next time.
- Read the man page for the command you found in step 9 and find and use the option to print only the word counts.
-
Go to the parent directory (
cd ..) and delete thebooksdirectory. Note that neither$ rm booksnor$ rmdir bookswill work.steve@clyde:~$ rm books rm: cannot remove 'books': Is a directory steve@clyde:~$ rmdir books rmdir: failed to remove 'books': Directory not emptyRead the man page for
rmto figure out how to recursively delete directories.