Bash’s `noclobber`: Your Accidental Overwrite Protector

Quick Tip

Bash’s `noclobber`: Your Accidental Overwrite Protector

Challenge: You’re working on the command line, perhaps piping output to a file, and accidentally overwrite an important existing file without realizing it.

The Solution: Use the `set -o noclobber` shell option to prevent accidental overwriting of files with redirection.

set -o noclobber

Why it works: When `noclobber` is enabled, attempting to redirect output to a file that already exists using `>` will result in an error, safeguarding your data from unintended modifications.

Pro-Tip: To temporarily disable `noclobber` for a single command, you can prefix the redirection with `!`. For example: !> existing_file

Linux Tips & Tricks | © ngelinux.com | 7/1/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted