Quick Tip
The `noclobber` Shield: Preventing Accidental Overwrites
Challenge: When using shell redirection (e.g., `>`), there’s always a risk of accidentally overwriting important files with empty output or unintended data.
The Solution: Utilize the `noclobber` shell option. This prevents redirection from overwriting existing files.
set -o noclobber
Why it works: When `noclobber` is enabled, any attempt to redirect output to a file that already exists will result in an error, safeguarding your data. To force an overwrite, you can use `>|`.
Pro-Tip: You can temporarily disable `noclobber` for a single command by prefixing it with `noclobber=”` or by using `>|` instead of `>`.
Linux Tips & Tricks | © ngelinux.com | 6/7/2026
