Solutions

Sort

The -n option specifies a numerical rather than an alphanumerical sort.

>

In the first example with >, the string ‘hello’ is written to testfile01.txt, but the file gets overwritten each time we run the command.

We see from the second example that the >> operator also writes ‘hello’ to a file (in this case testfile02.txt), but appends the string to the file if it already exists (i.e. when we run it for the second time).

Appending Data

Option 3 is correct. For option 1 to be correct we would only run the head command. For option 2 to be correct we would only run the tail command. For option 4 to be correct we would have to pipe the output of head into tail -n 2 by doing head -n 3 animals.csv | tail -n 2 > animals-subset.csv

Piping Commands

Option 4 is the solution. The pipe character | is used to connect the output from one command to the input of another. > is used to redirect standard output to a file. Try it in the shell-lesson-data/exercise-data/proteins directory!

Remove unneeded files

  1. This would remove .txt files with one-character names
  2. This is the correct answer
  3. The shell would expand * to match everything in the current directory, so the command would try to remove all matched files and an additional file called .txt
  4. The shell would expand . to match all files with any extension, so this command would delete all files