Note: The exercises here are meant for Linux and macOS. That doesn't mean that they cannot be executed in a Windows operating system but it might require some adaptation of the syntax.
From fairest creatures we desire increase,
That thereby beauty’s rose might never die,
But as the riper should by time decease,
His tender heir might bear his memory;
But thou, contracted to thine own bright eyes,
Feed’st thy light’s flame with self-substantial fuel,
Making a famine where abundance lies,
Thyself thy foe, to thy sweet self too cruel.
Thou that art now the world’s fresh ornament
And only herald to the gaudy spring,
Within thine own bud buriest thy content,
And, tender churl, mak’st waste in niggarding.
Pity the world, or else this glutton be,
To eat the world’s due, by the grave and thee.
Redirecting and appending
Exercise 1: Answer
Using echo and >, make files called line_1.txt and line_2.txt containing the first and second lines of Sonnet 1, respectively. Sonnet 1 can be found at the end of the page
Exercise 2: Answer
Replicate the original sonnet_1.txt (containing the first two lines of the sonnet) by first redirecting the contents of line_1.txt and then appending the contents of line_2.txt. Call the new file sonnet_1_copy.txt, and confirm using diff that it's identical to sonnet_1.txt
Exercise 3: Answer
Use cat to combine the contents of line_1.txt and line_2.txt in reverse order using a single command, yielding the file sonnet_1_reversed.txt.
Listing
Exercise 1: Answer
What’s the command to list all the files (and directories) that start with the letter s?
Exercise 2: Answer
What is the command to list all the files that contain the string onnet, long-form by reverse modification time?
Exercise 3: Answer
What is the command to list all files (including hidden ones) by reverse modification time, in long form?
Renaming, copying, deleting
Exercise 1: Answer
Use the echo command and the redirect operator > to make a file called foo.txt containing the text hello, world. Then, using the cp command, make a copy of foo.txt called bar.txt. Using the diff command, confirm that the contents of both files are the same.
Exercise 2: Answer
By combining the cat command and the redirect operator >, create a copy of foo.txt called baz.txt without using the cp command.
Exercise 3: Answer
Create a file called quux.txt containing the contents of foo.txt followed by the contents of bar.txt.
Exercise 4: Answer
How do rm nonexistent and rm -f nonexistent differ for a nonexistent file?
Summary
Exercise 1: Answer
By copying and pasting the text at the end of this file, use echo to make a file called sonnet_1_complete.txt containing the full (original) text of Shakespeare's first sonnet.
Exercise 2: Answer
Type the sequence of commands needed to create an empty file called foo, rename it to bar, and copy it to baz.