Skip to content

Lesson 6: Practice questions

Author: Stephan Sanders, PhD (UCSF)

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.

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 perl script in /data/classes/BTEP/unix_on_biowulf_2024_practice_sessions/lesson6_practice/.

Solution

mkdir treasure_hunt
cd treasure_hunt  
perl /data/classes/BTEP/unix_on_biowulf_2024_practice_sessions/lesson6_practice/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 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 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.