The `noclobber` Shell Option: Prevent Accidental Overwrites

Quick Tip

The `noclobber` Shell Option: Prevent Accidental Overwrites

Challenge: You’re running a script or manually redirecting output, and a simple mistake can lead to overwriting important files with unintended content.

The Solution: Use the `set -o noclobber` shell option to prevent accidental overwrites of existing files during redirection.

set -o noclobber

Why it works: When `noclobber` is enabled, attempting to redirect output (`>`) to a file that already exists will result in an error, not an overwrite. This acts as a safety net for your data.

Pro-Tip: To bypass `noclobber` for a specific redirection when you truly intend to overwrite, use `>| filename`.

Linux Tips & Tricks | © ngelinux.com | 5/21/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments