bash>禁止使用重定向(>)

sev*_*ine 1 bash

我的环境:

CentOS 6.5
bash 4.1.2(1)
Run Code Online (Sandbox Code Playgroud)

有时当我打算在文件中添加内容时,而不是

$ echo "xxx" >> mymemo.txt
Run Code Online (Sandbox Code Playgroud)

我错了

$ echo "xxx" > mymemo.txt
Run Code Online (Sandbox Code Playgroud)

导致备忘录丢失mymemo.txt.

我想知道是否有办法禁止使用重定向(>),但允许使用重定向(>>)?

tvm*_*tvm 6

你可以set -o noclobber在你的.bashrc.profile

如果设置,bash会阻止您在重定向时覆盖现有文件.

mint@mint ~ $ echo "foo" > test
bash: test: cannot overwrite existing file
Run Code Online (Sandbox Code Playgroud)