The issue "command not working on Mac" can stem from everything from permissions errors to terminal corruption, but the simplest fix is often restarting your Mac or checking the command’s syntax. If you’re seeing errors like "command not found" or the terminal freezing, you’ll need to troubleshoot step by step—starting with basic fixes before delving into deeper system checks. Most issues resolve with a few quick adjustments, but advanced corruption may require resetting your terminal or reinstalling macOS.

What You'll Need

  • A Mac running macOS (versions since Catalina, released in 2019).
  • Your Mac’s username and password (for account and app permissions).
  • The command you’re trying to run (e.g., `ls`, `open`, or a custom script).
  • Optional: A backup of your Terminal app or shell settings (if resetting).

Step-by-Step

  1. Check for typos or missing spaces. The most common reason a command fails is a typo or misplaced space. For example: ls- files (incorrect) vs. ls files (correct). Copy the command from the web or another source, then paste it into Terminal. Highlight any symbols or letters you’re unsure of and press ⌘+F to search within the terminal window.
  2. Run the command as an administrator. If you’re running a system-level command (e.g., modifying files globally), open Terminal, press ⌥+⌘+I, and enter the password. This forces Terminal to use elevated permissions. Note: Do this only if the command explicitly requires admin rights (e.g., `sudo ls`). Most user-level commands don’t need this.
  3. Verify the command exists in your PATH. Some commands (like `brew`, `git`, or custom scripts) aren’t in your system’s default search path. To check:
    1. Type which [command] (e.g., which ls). If it returns nothing, the command isn’t installed or isn’t in your PATH.
    2. Install the command if missing (e.g., brew install curl for `curl`).
  4. Restart Terminal. Close and reopen Terminal. If the issue persists, restarting clears temporary corruption. Alternative: Kill all Terminal processes in Activity Monitor (⌘+Space, type "Activity Monitor," press ⌘+Q to quit, then restart Terminal).
  5. Check for permission errors. Use the chmod or chown commands to fix file permissions:
    1. Navigate to the directory where the command operates (e.g., cd ~/Documents).
    2. Run: chmod +x script.sh (for executable files) or chown $USER /path/to/file (to grant ownership).
  6. Run macOS diagnostics. If the terminal freezes or crashes repeatedly, macOS may have underlying issues:
    1. Restart your Mac in Safe Mode (hold ⌘+S during startup).
    2. Check for known issues on Apple’s support site.
  7. Reset Terminal preferences (if stuck). Corrupted settings can break commands. Reset Terminal’s preferences:
    1. Open Terminal, then press ⌘+⇧+G to open the Go menu. Type ~/Library/Preferences and press Enter.
    2. Delete com.apple.Terminal.plist and restart Terminal.
  8. Reinstall Terminal (last resort). If the issue persists, reinstall the Terminal app:
    1. Open System Settings > Apps > App Store and uninstall Terminal.
    2. Search for "Terminal" in the App Store, download it, and reinstall.

Common Mistakes

  • Assuming all commands need admin rights. Run only if explicitly required (e.g., `sudo rm -rf`). Most user commands (like `ls`, `open`) work without it.
  • Editing files in Terminal without checking permissions. Commands like vi or nano may fail if you lack write permissions. Use chmod +w filename if needed.
  • Overwriting system files. Avoid running commands in directories like /bin or /usr unless you’re an admin and certain of the command’s safety.
  • Ignoring the error message. If a command fails with an error (e.g., "Permission denied"), the solution is often to adjust permissions or check the command’s validity.

Tips

  • Use the command history. Press ⌘+R to rerun a failed command from history. If the command was recently used, it might work after a restart.
  • Try a fresh Terminal window. If the terminal is unresponsive, open a new one (⌘+T or ⌘+N) and test the command.
  • Use `man` for command details. Type man [command] (e.g., man ls) to see proper usage and hidden flags.
  • Avoid running scripts from untrusted sources. If you’re testing a script, run it in a dedicated directory (e.g., ~/scripts) rather than your home folder to avoid errors.

Troubleshooting

  1. The command still fails after all steps. If you’ve checked permissions, syntax, and restarted, macOS corruption may be the issue. Perform a clean Terminal reinstall or reset:
    1. Open System Settings > General > Transfer or Reset Mac.
    2. Select "Reset Terminal" (not "Erase All Content and Settings"). This resets preferences without losing data.
  2. Terminal crashes repeatedly. Try running macOS in Safe Mode (as described earlier) or check for third-party apps interfering. Run this command in Terminal to list all running processes: top. Look for suspicious or resource-heavy apps.
  3. You’re using a custom shell (e.g., Zsh). If you switched to Zsh and commands stop working, reassign your shell to Bash: chsh -s /bin/bash.
  4. You’re on a Mac with macOS Ventura or later. Enable "Auto Unlock Terminal" in Terminal’s preferences (Terminal > Preferences > Profiles > Keyboard > Auto Unlock Terminal with Password or Touch ID).

Frequently Asked Questions

Why does "ls" work in one Terminal but not another?

The ls command works if it’s installed in your PATH. If you’re using a custom shell or installed tools separately (like brew), the command may not appear globally. Check with which ls or reinstall coreutils if missing.

How do I fix "command not found" for a system utility?

System utilities (like rm, mv) are usually included by default. If you see command not found, your shell might not be set to use the correct path. Run export PATH=$PATH:/bin:/usr/bin to include standard paths, or reinstall the shell.

Why does Terminal freeze when I run a command?

Terminal freezes if the command hangs (e.g., waiting for input, reading a large file, or failing silently). Use timeout 10 [command] to force it to stop after 10 seconds, or check the command’s documentation for known quirks.

How can I run a script without Terminal crashing?

Run scripts in a terminal with error handling: bash -o pipefail script.sh to catch errors, or redirect output: script.sh > output.log. Avoid running scripts in directories with complex permissions.

Will resetting Terminal preferences delete my custom aliases?

Resetting com.apple.Terminal.plist resets all preferences, including aliases. To save them, export them first: defaults export com.apple.Terminal ~/.TerminalPreferences.

Why does my custom command not work after reinstalling Terminal?

Custom commands (aliases or functions) require updating them in Terminal’s preferences or shell config files (e.g., ~/.zshrc or ~/.bash_profile). Reopen Terminal after editing these files.