- Create a new directory called
missing
under/tmp
.mkdir /tmp/missing
- Look up the
touch
program. Theman
program is your friend.man touch
- Use
touch
to create a new file calledsemester
inmissing
.touch /tmp/missing/semester
- Write the following into that file, one line at a time:
The first line might be tricky to get working. It's helpful to know that
#!/bin/sh curl --head --silent https://missing.csail.mit.edu
#
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.echo '#!/bin/sh' > /tmp/missing/semester echo 'curl --head --silent https://missing.csail.mit.edu' >> /tmp/missing/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)../semester
- Run the command by explicitly starting the
sh
interpreter, and giving it the filesemester
as the first argument, i.e.sh semester
. Why does this work, while./semester
didn't?sh semester
- Look up the
chmod
program (e.g. useman chmod
).man chmod
- Use
chmod
to make it possible to run the command./semester
rather 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.chmod 744 /tmp/missing/semester
- Use
|
and>
to write the "last modified" date output bysemester
into a file calledlast-modified.txt
in your home directory./tmp/missing/semester | grep last-modified | cut -f2- -d ' ' > ~/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.