This tip is for people who have ever hosed important files by using > when they meant to use >>. Add the following line to .bashrc:
set -o noclobber
The noclobber option prevents you from overwriting existing files with the > operator.
In some cases you may really want to overwrite the file. In this case, instead of turning noclobber off, you can use >! to force the file to be written.
% program >! file
hosed: 失败,(口语一点的用法)

本文介绍了一个简单的Bash配置技巧,通过在.bashrc中添加'set -o noclobber'来阻止使用 '>' 符号时意外覆写已有文件。此设置增强了文件操作的安全性,避免了因误操作导致的数据丢失。当确实需要覆写文件时,可以使用 '>'! '来强制执行。
750

被折叠的 条评论
为什么被折叠?



