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#
| Command | What it does |
|---|---|
pwd | Where am I |
ls -la | Everything here, including hidden files, with sizes |
cd path | Go there. cd .. goes up. cd - goes back |
cat file | Print the whole file |
head -20 file | The first twenty lines. Use this on anything large |
tail -f log | Follow a log as it is written. Ctrl+C to stop |
wc -l file | Count lines. The fastest way to check an export is complete |
grep pattern file | Every line containing pattern |
grep -rn pattern . | The same, through every file below here, with line numbers |
find . -name "*.csv" | Every CSV below here |
df -h | Disk space. The answer to a surprising number of faults |
Python#
| Command | What it does |
|---|---|
python3 --version | Prove which one you are running |
python3 script.py | Run it |
python3 | An interactive prompt. exit() leaves |
python3 -m venv .venv | Make an isolated environment for this project |
source .venv/bin/activate | Enter it (.venv\Scripts\activate on Windows) |
pip install package | Install into the active environment |
pip freeze > requirements.txt | Record exactly what is installed |
pip install -r requirements.txt | Recreate it somewhere else |
python3 -m http.server 8000 | Serve 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#
| Command | What it does |
|---|---|
git status | What has changed. Run this constantly |
git init | Start a repository here |
git add . | Stage everything as it currently is |
git commit -m "why" | Snapshot it |
git log --oneline | The history, newest first |
git diff | What has changed and not yet been staged |
git checkout . | Throw away uncommitted changes. Destructive |
git checkout abc1234 | Go and look at that commit |
git checkout main | Come back |
git switch -c name | Start a branch |
git remote -v | Where does this push to |
git push -u origin main | Push, and remember where |
git clone url | Get 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#
| Command | What it does |
|---|---|
node --version | Prove which one |
node script.mjs | Run it |
npm install | Install this project's dependencies |
npm ci | Install 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#
| Command | What it does |
|---|---|
arduino-cli board list | Which 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=115200 | Serial 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#
| Command | What it does |
|---|---|
ssh user@hostname.local | Get a shell on it |
ip addr | What address does it have |
hostname -I | Just the addresses |
sudo systemctl status showprop | Is my service running |
sudo systemctl restart showprop | Restart it |
sudo journalctl -u showprop -f | Follow its log |
sudo systemctl enable showprop | Start it on boot |
sudo raspi-config | The configuration menu |
sudo shutdown -h now | Shut down properly. Do this rather than pulling the plug |
vcgencmd measure_temp | Temperature. Throttling looks like a software fault |
Finding out what is going on#
| Command | What it does | |
|---|---|---|
ping 192.168.1.10 | Is it there at all | |
ip addr / ifconfig | My own addresses | |
netstat -tulpn / ss -tulpn | What is listening on which port | |
lsof -i :8000 | What has port 8000 | |
top or htop | What 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:
- Is it running the code I think it is? Add a print at the top and see it appear.
- Is it the machine I think it is?
hostname,pwd,git log --oneline -1. - Is the data what I think it is? Print the actual value and its type. Not the length.
- Did it ever work?
git log. If yes, what changed. - Is it a cable? It is a cable more often than any single software cause.
- 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".