Skip to content

Lesson 3 Practice

For today's practice, 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.

To begin create a directory called treasure_hunt in your class working directory and run the perl script from /data/classes/BTEP/B4B_2025/Module_1/Practice_Sessions/Practice_L4 in the treasure_hunt directory.

Solution
mkdir treasure_hunt
cd treasure_hunt  
perl /data/classes/BTEP/B4B_2025/Module_1/Practice_Sessions/Practice_L4/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  
    
  2. Save the last line of openTheBox.txt to a new file called finallyfinished.txt without copying and pasting.

    Solution
    tail -n 1 openTheBox.txt > finallyfinished.txt 
    
  3. Now append the first line of openTheBox.txt 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.