Guide

Is This Shell Command Safe? How to Check Before Running

Short answer: is this shell command safe? Do not guess: do not run a command you cannot explain. Paste it into the Shell Command Risk Explainer, which splits it into parts, explains every command, flag and argument in plain English, rates it Info, Caution or Danger with the exact reason, and suggests a safer alternative. The command is never run, links in it are never opened, and nothing is uploaded.

Why this matters

You copy shell commands from tutorials, README files, forum answers, chat messages and AI assistants. A shell command runs with your permissions: it can delete files, change permissions, download and execute code, or open a door to your machine. A single character can turn a cleanup into a disaster.

AI assistants make this more urgent (see insecure patterns in AI-generated code). They produce confident, plausible commands quickly, and people paste them without reading. A second pair of eyes before you press Enter is cheap.

The patterns that deserve the most attention

1. Piping a download into a shell

curl -fsSL https://example.com/install.sh | sudo bash

This runs whatever the server sends, unread, and with sudo it runs as an administrator. Viewing the URL in a browser first is helpful but not bulletproof: a server can send different content to a program than to a browser. A researcher's write-up on why curl | bash is a bad habit demonstrates how a server can behave differently when it detects piping.

Safer: download the script to a file, read it, optionally check its checksum (see the Hash Generator), then run it.

2. Recursive delete with a risky target

rm -rf "$DIR/"*        # dangerous if $DIR is empty
rm -rf ~/              # deletes your home folder
rm -rf /               # the whole system

An empty or unset variable can turn rm -rf "$DIR/"* into rm -rf /*. The explainer flags this because $DIR could be empty, not because it is.

Safer: check the variable first (${DIR:?} makes the shell stop if it is empty), try without -f, or list the files first.

3. Wide-open permissions

chmod -R 777 /var/www

Gives every user read, write and execute on everything below. Use the Chmod Calculator to choose the minimum permission you actually need (see chmod 755, 644 and 600 explained).

4. Writing to a disk device

dd if=/dev/zero of=/dev/sda
echo hi > /dev/sda
mkfs.ext4 /dev/sda1

These overwrite or format a disk. The device name matters enormously, and a wrong letter destroys the wrong drive.

5. Hard-to-undo version control and container actions

git push --force, git reset --hard, docker run --privileged, mounting / into a container, kubectl delete. These are not always wrong, but they are the commands people regret.

6. Fork bombs, reverse shells and persistence

A fork bomb such as :(){ :|:& };: exhausts the system. Reverse shells hand your machine to someone else. Commands that edit crontab, shell startup files or systemctl services can leave something running long after the command finishes.

7. Disguised commands

Look-alike letters and invisible characters can make a command read differently from how it runs. If a command came from a web page or chat, scan it with the Hidden Unicode Detector (see How to detect hidden Unicode characters).

Is this shell command safe? How to check with the Risk Explainer

  1. Open the Shell Command Risk Explainer.
  2. Paste a bash or zsh command or a short script (up to 100,000 characters).
  3. Read the Annotated breakdown: each command, flag and argument explained in plain English, with its risk level (Info, Caution or Danger) and the reason.
  4. Check What it may touch: the files and folders, network addresses, and processes or services involved.
  5. Read Safer alternatives for the same task.
  6. If something is flagged Danger, stop and work out why before going further.

What it understands

  • Parsing: quotes and escapes, pipes, &&, ||, ;, background &, subshells and $( ) or backticks, redirects, here-strings and here-documents, variable assignments in front of a command, and line continuations. Text inside quotes is treated as text, not as a command.
  • About 110 commands with their common flags: among them rm, mv, cp, dd, mkfs, chmod, chown, find (with -delete and -exec), xargs, tar, curl, wget, sudo, su, ssh, scp, rsync, git, docker, kubectl, npm, pip, systemctl, iptables, crontab, eval, source, export, shred and truncate.
  • Danger rules: recursive delete of /, ~, $HOME, * or a possibly empty variable; a download piped into a shell; chmod -R 777; dd or a redirect to a disk device; formatting a disk; a fork bomb; a reverse shell; and sudo combined with any of these.
  • Caution rules: actions that are hard to undo or widen access, such as git push --force, git reset --hard, docker run --privileged, mounting / into a container, kubectl delete, unpinned or URL installs, global installs, --force flags, firewall and service changes, and exporting what looks like a secret (if one has already leaked, see what to do about a leaked API key).

Limits you must understand

A clean result is not a safety guarantee. The page itself says it is a second pair of eyes, not a guarantee.

  • It cannot know the value of a variable, your aliases, shell functions, or the folder you will run the command in.
  • It does not know what a script, program or downloaded file does once it runs. It never fetches anything, so it cannot tell whether a URL is safe.
  • Commands it does not know are shown with generic notes only. An unknown command is not proof of safety, and tools outside its list of about 110 commands (for example, many cloud and infrastructure command-line tools) are not modelled in depth.
  • It handles bash and zsh. Fish, PowerShell and Windows cmd and unusual syntax are not covered, and very large scripts may only be partly analysed. A parse note appears when the text looks incomplete.
  • A result of Info or Caution only means that none of the built-in Danger rules matched.
  • The breakdown lists the first 300 commands, while the overall risk covers all of them.

A safe habit in five steps

  1. Read it. If you cannot explain every part, do not run it.
  2. Paste it into the explainer and read the reasons.
  3. Check for hidden characters if it came from a web page, chat or AI tool.
  4. Test safely: use a throw-away container or virtual machine, or add a dry-run flag (--dry-run, -n) when the command supports one.
  5. Run with the least privilege. Avoid sudo unless it is truly needed.

Frequently asked questions

Is curl | bash safe? It is only as safe as the server and your trust in it. It runs unread code. Download, read, then run.

Is rm -rf always dangerous? It is powerful and irreversible. It is dangerous when the target is broad, a variable could be empty, or you run it as an administrator.

Does the tool run my command? No. It reads the command as text on your device. Nothing is executed, fetched, stored or placed in the URL.

Can I trust AI-generated commands? Treat them like any untrusted command: explain them, understand them, and test them safely first.

What if the result says Info? It means no built-in Danger rule matched. It does not mean the command is safe.

Related tools and guides

Sources and further reading