Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 重導向輸出提示 cannot overwrite existing file 解決方法

編輯:Linux 教學

錯誤情境

echo "test" > file.txt
# bash: file.txt: cannot overwrite existing file

原因

Shell 環境啟用了 noclobber 選項 (set -o noclobber),防止 > 覆蓋既有檔案。

解決:關閉 noclobber

set +o noclobber

臨時強制覆蓋 (不關閉選項)

echo "test" >| file.txt   # 加上 | 符號強制覆蓋

永久關閉 (寫入 ~/.bashrc 或 /etc/profile)

# 註解或移除
# set -o noclobber

查看目前設定

set -o | grep noclobber
# noclobber   on  表示啟用
# noclobber   off 表示關閉
Copyright © Windows教程網 All Rights Reserved