Quick Tip
The `noclobber` Shield: Prevent Accidental Overwrites
Challenge: When redirecting output to a file using `>`, you can accidentally overwrite existing data if you’re not careful. This is especially risky in scripts or when working quickly.
The Solution: Use the `noclobber` shell option to prevent accidental overwrites.
set -o noclobber
Why it works: With `noclobber` set, attempting to redirect output to a file that already exists using `>` will result in an error, preventing data loss. To force an overwrite when this option is set, you can use `>!`.
Pro-Tip: To disable `noclobber`, simply run set +o noclobber. You can also add set -o noclobber to your shell’s configuration file (e.g., ~/.bashrc or ~/.zshrc) to have it enabled by default.
Linux Tips & Tricks | © ngelinux.com | 6/17/2026
