DevTech101

DevTech101

Protecting Files From Overwriting Mistakenly

To set protection on, run the below.

set -o noclobber

To make it permanent just add to your .bashrc

echo 'set -o noclobber' >> ~/.bashrc

An example how things will work after noclobber is set.

$ echo test > testfile1
bash: testfile1: cannot overwrite existing file

To forcibly overwrite the file, just add the !, like the example below.

$ echo test >! testfile1

To unset in your current shell, just run the below.

set +o noclobber

To unset totally from every new shell (if it was added to .bashrc) just remove the setting from .bashrc.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
%d bloggers like this: