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?
ask for comfirmation when file is replaced using a redirection
bash;io redirection;alias
I don't think there's a way to get the exact behavior of -i, but I have noclobber set which prevents overwriting already existing files. See this page for a usage example.You can try out the command like this (and if you like it, include it in your startup file)$ set -o noclobberExample:$ ls > ls.out$ set -o noclobber$ ls > ls.outbash: ls.out: cannot overwrite existing file$Update:As @jsbillings mentions in a helpful comment below, to override the noclobber in bash one can use >|Since I primarily use tcsh (a csh variant), the override operator is >!