Downloading a file
Exercise 1: Answer
Use the command curl -I www.learnenough.com to fetch the HTTP header for the Learn Enough website. What is the HTTP status code of the address? How does this differ from the status code of https://www.learnenough.com/
Exercise 2: Answer
Using ls, confirm that sonnets.txt exists on your system. How big is it in bytes? If it Doesn’t exist, you can create it from Sonnets page.
Exercise 3: Answer
Using the -h ("human-readable") option to ls, list the long form of the sonnets file with a human-readable byte count.
Exercise 4: Answer
Suppose you wanted to list the files and directories using human-readable byte counts, all, by reverse time-sorted long-form. Why might this command be the personal favourite of every engineer?
Making heads and tails of it
Exercise 1: Answer
By piping the results of tail sonnets.txt through wc, confirm that (like head) the tail command outputs 10 lines by default.
Exercise 2: Answer
By experimenting with different values of n, find a head command to print out just enough lines to display the first sonnet in its entirety
Exercise 3: Answer
Pipe the results of the previous exercise through tail (with the appropriate options) to print out only the 14 lines composing Sonnet 1.
Exercise 4: Answer
To simulate the creation of a log file, run ping http://learnenough.com > learnenough.log in one terminal tab. (The ping command "pings" a server to see if it's working.) In a second tab, type the command to tail the log file. (At this point, both tabs will be stuck, so once you've gotten the gist of tail -f you should use the technique from Box 4 to get out of trouble.)
Less is more
Exercise 1: Answer
Run less on sonnets.txt. Go down three pages and then back up three pages. Go to the end of the file, then to the beginning, then quit.
Exercise 2: Answer
Search for the string “All” (case-sensitive). Go forward a few occurrences, then back a few occurrences. Then go to the beginning of the file and count the occurrences by searching forward until you hit the end. Compare your count to the result of running grep All sonnets.txt | wc.
Exercise 3: Answer
Using less and / (“slash”), find the sonnet that begins with the line “Let me not”. Are there any other occurrences of this string in the Sonnets?
Exercise 4: Answer
By searching for the string “sort” in the man page for ls, discover the option to sort files by size. What is the command to display the long form of files sorted so the largest files appear at the bottom?
Grepping
Exercise 1: Answer
By searching man grep for “line number”, construct a command to find the line numbers in sonnets.txt where the string “rose” appears.
Exercise 2: Answer
You should find that the last occurrences of “rose” is (via “roses”) on line 2203. Figure out how to go directly to this line when running less sonnets.txt.
Exercise 3: Answer
By piping the output of grep to head, print out the first (and only the first) line in sonnets.txt containing “rose”.
Exercise 4: Answer
In previous exercise, we saw two additional lines that case-insensitively matched “rose”. Execute a command confirming that both of the lines contain the string “Rose” (and not, e.g., “rOSe”).
Exercise 5: Answer
Write a command confirming that the number of lines matching “Rose” but not matching “rose” is equal to the expected 2.
Summary
Exercise 1: Answer
Pipe history to less to examine your command history. What was your 17th command?
Exercise 2: Answer
By piping the output of history to wc, count how many commands you’ve executed so far.
Exercise 3: Answer
By piping the output of history to grep, determine the number for the last occurrence of curl.
Exercise 4: Answer
Use the result from the previous exercise to re-run the last occurrence of curl.
Exercise 5: Answer
What do the O and L options in curl mean?