Computer Sciencefor Theatre & Technical Direction

For the floor

The field card

The commands, on one page, for when you are standing somewhere with a laptop and no signal. Shell, Python, git, Node, Arduino, a Pi over the network, and the order to check things in when something is wrong.

The commands, on one page, for when you are standing somewhere with a laptop and no signal. Print it. Nothing here needs the internet.

Getting oriented#

CommandWhat it does
pwdWhere am I
ls -laEverything here, including hidden files, with sizes
cd pathGo there. cd .. goes up. cd - goes back
cat filePrint the whole file
head -20 fileThe first twenty lines. Use this on anything large
tail -f logFollow a log as it is written. Ctrl+C to stop
wc -l fileCount lines. The fastest way to check an export is complete
grep pattern fileEvery line containing pattern
grep -rn pattern .The same, through every file below here, with line numbers
find . -name "*.csv"Every CSV below here
df -hDisk space. The answer to a surprising number of faults

Python#

CommandWhat it does
python3 --versionProve which one you are running
python3 script.pyRun it
python3An interactive prompt. exit() leaves
python3 -m venv .venvMake an isolated environment for this project
source .venv/bin/activateEnter it (.venv\Scripts\activate on Windows)
pip install packageInstall into the active environment
pip freeze > requirements.txtRecord exactly what is installed
pip install -r requirements.txtRecreate it somewhere else
python3 -m http.server 8000Serve this folder over HTTP. Endlessly useful on site
python3 -c "print(1+1)"Run one line without a file

Always use a virtual environment for a project. Installing globally works until two projects want different versions of the same library, and then it does not, on the day.

git#

CommandWhat it does
git statusWhat has changed. Run this constantly
git initStart a repository here
git add .Stage everything as it currently is
git commit -m "why"Snapshot it
git log --onelineThe history, newest first
git diffWhat has changed and not yet been staged
git checkout .Throw away uncommitted changes. Destructive
git checkout abc1234Go and look at that commit
git checkout mainCome back
git switch -c nameStart a branch
git remote -vWhere does this push to
git push -u origin mainPush, and remember where
git clone urlGet a copy of somebody else's

If you are lost: git status tells you where you are, and git stash puts your changes safely aside so you can look at something else. Nothing committed is ever lost, which is the whole reason to commit often.

Node#

CommandWhat it does
node --versionProve which one
node script.mjsRun it
npm installInstall this project's dependencies
npm ciInstall exactly what the lockfile says. Use this on a show machine
npm run <script>Run a script from package.json
npx <tool>Run a tool once without installing it globally
npm ls <package>Which version is actually installed, and why

On a show machine, npm ci rather than npm install. The first installs exactly what the lockfile records; the second is allowed to resolve something newer, which is how a machine that worked yesterday stops working today with nobody having changed anything.

Arduino#

CommandWhat it does
arduino-cli board listWhich boards are connected, and on which port
arduino-cli compile --fqbn arduino:avr:uno sketch/Compile without uploading
arduino-cli upload -p /dev/ttyUSB0 --fqbn arduino:avr:uno sketch/Upload
arduino-cli monitor -p /dev/ttyUSB0 -c baudrate=115200Serial monitor
ls /dev/tty.*Find the port on macOS (/dev/ttyUSB* or ttyACM* on Linux)

If the board is not detected: the cable, first, always. Then the port. Then the driver. In that order, because that is the order of how often each is the cause.

A Raspberry Pi, over the network#

CommandWhat it does
ssh user@hostname.localGet a shell on it
ip addrWhat address does it have
hostname -IJust the addresses
sudo systemctl status showpropIs my service running
sudo systemctl restart showpropRestart it
sudo journalctl -u showprop -fFollow its log
sudo systemctl enable showpropStart it on boot
sudo raspi-configThe configuration menu
sudo shutdown -h nowShut down properly. Do this rather than pulling the plug
vcgencmd measure_tempTemperature. Throttling looks like a software fault

Finding out what is going on#

CommandWhat it does
ping 192.168.1.10Is it there at all
ip addr / ifconfigMy own addresses
netstat -tulpn / ss -tulpnWhat is listening on which port
lsof -i :8000What has port 8000
top or htopWhat is using the processor
`ps aux \grep python`Is my script actually running
kill -9 <pid>Stop it, unkindly. Try Ctrl+C first
`dmesg \tail`What the kernel just noticed. USB problems appear here

When something is wrong#

In this order, because it is the order of likelihood:

  1. Is it running the code I think it is? Add a print at the top and see it appear.
  2. Is it the machine I think it is? hostname, pwd, git log --oneline -1.
  3. Is the data what I think it is? Print the actual value and its type. Not the length.
  4. Did it ever work? git log. If yes, what changed.
  5. Is it a cable? It is a cable more often than any single software cause.
  6. What does the error message actually say? Read it from the bottom. It names the file and the line, and it is free.

The two keystrokes#

  • Ctrl+C stops the running program. The most important thing on this page.
  • Tab completes a name. It prevents most typing errors in paths, which is most "file not found".