linux 清空一個大文件(上G的)一般有這麼幾種方法:
- cat /dev/null > nohup.log
- cp /dev/null > nohup.log
- echo "" > nohup.log
但是今天在嘗試這幾個命令的時候發現始終無法清空。
最終發現問題在nohup.log的生成命令那裏:
nohup xxx > nohup.out &
問題就在 > ,需要使用 >> 追加模式才能使用上述三個命令清空。
正確方式:
nohup xxx >> nohup.out &
其實,應該將nohup.out進行拆分。或者不輸入到nohup.out。因爲畢竟程序裏面已經使用了log庫。