-
Create a new directory called
missingunder/tmp.Solution: We can use
mkdir /tmp/missingormkdir -p /tmp/missing. -
Look up the
touchprogram. Themanprogram is your friend.Solution: We can use
man touchortldr touch. -
Use
touchto create a new file calledsemesterinmissing.Solution:
Run the following commands in your terminal.
cd /tmp/missing touch semesterOr using a single comand.
touch /tmp/missing/semester
-
Write the following into that file, one line at a time:
#!/bin/sh curl --head --silent https://missing.csail.mit.eduThe first line might be tricky to get working. It's helpful to know that
#starts a comment in Bash, and!has a special meaning even within double-quoted (") strings. Bash treats single-quoted strings (') differently: they will do the trick in this case. See the Bash quoting manual page for more information.Solution:
Run the following commands in your terminal.
echo '#!/bin/sh' > semester echo 'curl --head --silent https://missing.csail.mit.edu' >> semester
-
Try to execute the file, i.e. type the path to the script (
./semester) into your shell and press enter. Understand why it doesn't work by consulting the output ofls(hint: look at the permission bits of the file).Solution:
Run the following commands in your terminal.
./semester
And the terminal returns the following error.
zsh: permission denied: ./semester
-
Run the command by explicitly starting the
shinterpreter, and giving it the filesemesteras the first argument, i.e.sh semester. Why does this work, while./semesterdidn't?Solution: Because the current user of the terminal does not have executable permissions to this file. However the current user has permssions to use
shcommand to run the file and the filename is used as an argument ofshcommand. -
Look up the
chmodprogram (e.g. useman chmod).Solution: We can use
man chmodortldr chmod. -
Use
chmodto make it possible to run the command./semesterrather than having to typesh semester. How does your shell know that the file is supposed to be interpreted usingsh? See this page on the shebang line for more information.Solution: We can use
chmod +x semesterto tackle the problem. -
Use
|and>to write the "last modified" date output bysemesterinto a file calledlast-modified.txtin your home directory.Solution:
Run the following commands in your terminal.
./semester | grep -i last-modified | cut -d' ' -f2- > last-modified.txt
-
Write a command that reads out your laptop battery's power level or your desktop machine's CPU temperature from
/sys. Note: if you're a macOS user, your OS doesn't have sysfs, so you can skip this exercise.Solution:
Run the following commands to check the power level.
cat /sys/class/power_supply/BAT0/capacity
Run the following commands to check the CPU temperature.
cat /sys/class/thermal/thermal_zone0/temp