shellstreak

Dangerous shell commands to never run (or approve)

Updated · Every command on this page ran in our practice shell

Short answer

Never run or approve rm -rf with a variable or wildcard you haven't checked, curl ... | sh, chmod -R 777, git push --force on a shared branch, git reset --hard, git clean -fdx or git restore . with uncommitted work, git commit --no-verify, rm -rf .git, or a > redirect onto a file you meant to keep. Preview first: ls the pattern, read the script, run git status.

Whether you're pasting from a forum or approving an AI agent's plan, a few commands deserve a second look every time. None of them are evil: each has legitimate uses. They're dangerous because one typo or one wrong assumption makes them irreversible. The examples here are safe previews you can run in the sandbox.

rm -rf with a variable or wildcard

rm -rf deletes without asking, recursively. With a variable it's worse: if $BUILD_DIR is unset, rm -rf $BUILD_DIR/* becomes rm -rf /*. Modern GNU rm refuses a bare /, but /* isn't protected. Echo the command first to see what it really expands to. In scripts, start with set -u and write rm -rf -- "${BUILD_DIR:?}"/*, so an unset or empty variable stops the script.

example
learner@shellstreak:~$ echo "rm -rf $BUILD_DIR/*"
rm -rf /*

Preview a wildcard before deleting

Before any rm with a wildcard, run the same pattern with ls. If the list surprises you, the delete would have too.

example
learner@shellstreak:~$ ls site/build/*.map
site/build/app.js.map
site/build/style.css.map

> onto a file you meant to keep

> replaces a file's contents without warning. cat extra.txt > .env doesn't add settings, it erases the old ones. Use >> to append, and turn on set -o noclobber if you want the shell to refuse to overwrite files.

example
learner@shellstreak:~$ cat site/extra-settings.txt >> site/.env && cat site/.env
SITE_NAME=Pebble Bakery
PORT=3000
CACHE=on
DEBUG=false
LOG_LEVEL=info

curl ... | sh

sh install.sh runs every command in a script. curl URL | sh (often written curl -fsSL URL | sh; the flags only make curl quiet and follow redirects) downloads a script and pipes it straight into a shell. That runs code nobody has read, with your permissions. If the server is compromised, or the download is cut off halfway, you run whatever arrived. Download to a file, read it, then run it.

chmod -R 777

chmod -R 777 dir: 777 gives every user on the machine read, write and execute permission, and -R applies it to every file below. It "fixes" permission errors by removing all protection. Grant the one permission that's missing instead, like chmod +x script.sh.

git reset --hard with uncommitted work

git reset --hard overwrites your working files with the last commit. Uncommitted edits are gone, and git can't bring them back. Run git status first: if anything is modified, commit it or git stash it.

example
learner@shellstreak:~/kiosk$ git status -s
 M src/cart.js
 M src/config.js
 D tests/cart.test.js
?? src/discount.js

git push --force

git push --force replaces the remote branch with your copy, deleting any commits others pushed in the meantime. If you must rewrite a branch only you use, prefer git push --force-with-lease --force-if-includes, or pin the commit you reviewed: --force-with-lease=my-branch:<sha>. Plain --force-with-lease is weaker than it sounds: any background git fetch (IDEs and agents do this) refreshes the lease, so it can overwrite commits you never saw. Never force-push a shared branch like main.

git clean -fdx, git restore . and git stash clear

git clean -fdx force-deletes every untracked and ignored file: local settings, notes, downloaded data. git restore . (or git checkout .) throws away every unstaged edit in the folder. git stash clear deletes all stashes. None of these leave a reflog entry, so there's no undo. Run git status and git stash list first, and restore only the files you mean.

example
learner@shellstreak:~/kiosk$ git status -s
 M src/cart.js
 M src/config.js
 D tests/cart.test.js
?? src/discount.js

Expiring the reflog: git reflog expire and git gc

The reflog is how you get lost commits back after a bad reset or force-push. git reflog expire --expire=now --all && git gc --prune=now empties it and deletes every commit nothing else points to, which are exactly the commits you'd recover. Refuse it as a "cleanup", above all in the middle of a recovery.

find -delete in the wrong place

find runs its tests left to right, so find . -delete -name "*.tmp" deletes everything before it ever checks the name. Put actions last, and run the same find without -delete first.

git commit --no-verify

git commit --no-verify (or -n) skips pre-commit and commit-msg hooks: the linter, the tests, the secret scanner. When a hook blocks a commit, it has found something. Fix that instead of skipping the check.

sudo to get past an error

sudo runs a command as root, with no permission checks at all. Use it on the one command that needs it, after reading that command, and never to make an error you don't understand go away. A root shell (sudo -s) turns every later typo into a root typo.

Deleting .git

The hidden .git folder is the repository: every commit, branch and stash. rm -rf .git to "fix" a git error throws away the whole history. Look at the error with git status and git log instead.

example
learner@shellstreak:~/kiosk$ ls -a
.
..
.git
README.md
scripts
src
tests

Check yourself

One real exercise from the “Supervising an AI coding agent” unit. No account needed.

The agent wants to empty site/build with rm -rf. Do it more carefully: first preview what site/build/* matches with ls, then delete those files with plain rm, keeping the folder itself and site/src.

What's checked: the files site/build/index.html, site/build/app.js, site/build/app.js.map, site/build/style.css, site/build/style.css.map, site/build/.gitkeep, site/src/index.html, site/src/style.css.

Common mistakes

  • Approving a long command chain because the first part looked fine. Read every step after && and |.

  • Trusting that a variable is set because it was set in another terminal.

  • Using sudo to get past an error you don't understand. It removes the last safety check.

  • Fixing a rejected push with --force instead of pulling first.

Questions

Is rm -rf / still dangerous on modern Linux?+

GNU `rm` refuses `rm -rf /` by default (`--preserve-root`), but not `rm -rf /*` or `rm -rf ~`, and other systems may not protect you at all. Treat any recursive delete near `/` or `~` as dangerous.

How do I make rm ask before deleting?+

Use `rm -i`, which asks about each file, or `rm -I`, which asks once before deleting many files or a folder.

Should I let an AI agent run commands without approval?+

Only read-only commands (`git status`, `git diff`, `ls`, `grep`), unless it runs in a sandbox, container or separate worktree you can throw away. Don't start it from a shell that holds production credentials. Anything that deletes, installs, runs project code, skips hooks, rewrites history or pushes needs a human to approve it, and `main` should be protected on the server.

Reading is step one. Now make it stick.

Practise this in a five-minute lesson with instant feedback. No account needed.

Practise it now