LoginSignup
18
9

More than 5 years have passed since last update.

bash > リダイレクション > ファイル上書きを禁止、追記だけにする > set -o noclobber

Last updated at Posted at 2015-02-23

動作環境

CentOS 6.5にてbashを使用



メモをecho コマンドで追記することがたびたびある。
echo "memo" >> mymemo.txt

上記をやるつもりが

echo "memo" > mymemo.txt

としてしまい、mymemo.txtの中身を飛ばしたことが何回かある。

こういう経緯から既存ファイルに対してリダイレクションにて">"を禁止して、">>"を許可する設定があるかSOにて聞いてみた (bash > prohibit to use redirection (>))。



.bashrc.profileなどにて
set -o noclobber

とすればいいとのこと。

新規ファイルでは">"が使えて、既存ファイルでは">"は使えなくなる。">>"はどちらのファイルでも使える。

18
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
9