Understanding Terminal Commands
16 minIntermediateHTML · CSS · JS
In this lesson
- ▸Explain what common commands read, write and change
- ▸Read npm error output and trace it back to
package.json - ▸Recognise destructive commands before you (or an agent) run them
The big idea
A terminal command is code that runs with your permissions on your files. Treat every suggested command like a code change: know what it reads, what it writes, and whether it can be undone.
Assistants suggest terminal commands constantly, and agent tools can run them for you after you approve. Approving a command you don't understand is like merging code you haven't read. Here's what the everyday ones actually do.
- npm install
- Reads
package.json(andpackage-lock.json), downloads the listed packages intonode_modules, and may update the lockfile. Packages can run their own install scripts, sonpm install some-namemeans trusting that package — check it exists and is spelled right; assistants can suggest package names that don't exist. - npm run dev
- Runs whatever command is under
"dev"in thescriptsofpackage.json. Usually it starts a development server that keeps running until you press Ctrl+C. Nothing magic: openpackage.jsonto see what it runs. - git status
- Read-only. Shows your branch, which files are changed, staged or untracked. Safe to run any time — run it before and after an agent edits your project.
- rm -rf <path>
- Removes files and folders recursively and forcefully: no confirmation, no recycle bin.
rm -rf node_modulesis common (you can reinstall), but a wrong path — or an empty variable inrm -rf $DIR/— can delete things you can't get back. - git reset --hard / git push --force
reset --hardthrows away uncommitted changes.push --forceoverwrites the history on the remote, which can erase teammates' work. Neither should be run casually.
Reading error output
Terminal errors look scary because they're long. Read from the top, find the first line that says what went wrong, and ignore the log-file noise at the end. Two npm classics (shortened; exact wording varies between npm versions — older versions print npm ERR!):
$ npm run dev
npm error code EJSONPARSE
npm error JSON.parse Failed to parse JSON data.
npm error JSON.parse Note: package.json must be actual JSON, not just JavaScript.package.json has a syntax error — often a trailing comma or a comment, which JSON doesn't allow.
$ npm run dev
npm error Missing script: "dev"
npm error
npm error To see a list of scripts, run:
npm error npm runThe file is valid, but there's no "dev" entry in scripts. The assistant assumed a script your project doesn't have.
command not found— the program isn't installed, or isn't on yourPATH(for project tools, run them throughnpm runornpx).EADDRINUSE— something is already listening on that port; probably your dev server is already running in another terminal.ENOENT— "no such file or directory": a path is wrong, or you're in the wrong folder (check withpwd).
Never paste destructive commands blindly
Before running anything an assistant suggests: can you say what it changes? Can it be undone? Is it touching the path you think? Be extra careful with rm -rf, sudo, git reset --hard, git push --force, git clean, and curl … | sh (which runs a script from the internet without showing it to you). Commit or stash your work before letting an agent run anything big, and don't approve commands in bulk.
There's no real terminal in this lesson. The preview reads package.json the way npm does and shows what npm run … would do — a safe place to practise reading it.
An assistant said: "Run npm run dev to start the Vite dev server." Your terminal printed the EJSONPARSE error above. The preview shows the same problem.
1. Fix the JSON syntax error in package.json (an assistant edited it earlier).
2. Run it again in your head: now npm would say Missing script: "dev". Add a "dev" script that starts Vite's dev server — the command is just vite.
Don't remove the existing scripts or dependencies.
Checks
- package.json is valid JSON
- Has a dev script that starts Vite
- Existing scripts and dependencies are kept
Check understanding
What you learned
- ✓
npm run <name>runsscripts[name]frompackage.json— read the file to know what runs. - ✓Read terminal errors from the top; codes like
EJSONPARSE,ENOENT,EADDRINUSEtell you where to look. - ✓
git statusis always safe;rm -rf,reset --hard,push --force,sudoandcurl | shneed full attention. - ✓Never paste or approve a command you can't explain.
Console output from your code appears here.