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

时间:2015-02-23 00:48:58

标签: bash

我的环境:

CentOS 6.5
bash 4.1.2(1)

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

$ echo "xxx" >> mymemo.txt

我误输了

$ echo "xxx" > mymemo.txt

导致mymemo.txt中的备忘录丢失。

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

1 个答案:

答案 0 :(得分:6)

您可以在set -o noclobber.bashrc

中使用.profile

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

mint@mint ~ $ echo "foo" > test
bash: test: cannot overwrite existing file
相关问题