Skip to content

Unix Review Practice Session

Author: Stephan Sanders, PhD (UCSF)

In this exercise, we are going to embark on a Unix treasure hunt created by the Sanders Lab at the University of California San Francisco. Note: the treasure hunt materials can be obtained directly from the Sanders lab code repository linked above.

Note to start at the /data/username folder for this exercise (replace username with the student account ID). To begin create a directory called treasure_hunt in your data directory (ie. /data/username) and change into it. Next, run the treasureHunt_v2.pl perl script in /data/classes/BTEP.

Solution
mkdir treasure_hunt
cd treasure_hunt  
perl /data/classes/BTEP/treasureHunt_v2.pl  
ls -l

Read the first clue and begin.

Recommendation: Create an environment variable to store the path to the treasure hunt directory to facilitate movement through the directory.

Solution
THUNT=`pwd`  
echo $THUNT 

When you have found the treasure, answer or do the following:

  1. How many words are in the last line of the file containing the teasure?
Solution
tail -n 1 openTheBox.txt | wc -w  
  1. Save the last line to a new file called finallyfinished.txt without copying and pasting.
Solution
tail -n 1 openTheBox.txt > finallyfinished.txt 
  1. Now append the first line to the same file that you just saved the last line.
Solution
head -n 1 openTheBox.txt >> finallyfinished.txt 

Congratulations! You have found the treasure and have gained some useful unix practice throughout your hunt.