I'm a careless terminal driver scared of accidentally deleting files, hence using some aliases like alias rm='rm -i'
for rm
, mv
, cp
. How can I get a similar confirmation behavior for file redirections (e.g echo "I'm silly" > very_important_file.txt
).
The common case is that I usually use replace (>
) instead of append (>>
) and so I ended up accidentally deleting some mid-important files. What are your suggestions?
-i
options and settingnoclobber
are temporary workarounds, but use them with caution - if they just encourage you to be more careless you'll run into trouble the day one of those settings gets reset or you have to use someone else's system. If you plan to spend any non-trivial amount of time in the terminal, a better protection is to train yourself to think about what you are doing before you press the enter key. I've learned my lessons from accidental terminal goofs, but most of them were not serious because I had backups.noclobber
orcp -i
is irresponsible.-i
andnoclobber
are nothing like seatbelts because they change the way basic commands work, whereas fastening a seatbelt doesn't cause your car to refuse to go into reverse or ask for confirmation every time you step on the accelerator. (... continued ...)-i
when appropriate, and never assume that the system has it aliased, nor do I advocate getting into the habit of assuming so. The way I see it, blindly assuming the car will fasten your seatbelt for you (or the system hasnoclobber
set) is much more irresponsible.