使用 vi/vim 編輯檔案時,若上次編輯異常中斷(斷電、SSH 斷線、強制關閉),會殘留交換檔(.swp),再次開啟同檔案時顯示 E325: ATTENTION 警告。本文說明警告內容解讀、三種處理選項(恢復/刪除/放棄)、標準解決步驟與預防建議。
E325: ATTENTION
Found a swap file by the name "/etc/.profile.swp"
owned by: root dated: Wed Jul 14 10:01:10 2010
file name: /etc/profile
modified: YES
user name: root host name: zhaoyang-laptop
process ID: 1934
While opening file "/etc/profile"
dated: Thu Apr 29 20:18:30 2010
(1) Another program may be editing the same file.
If this is the case, be careful not to end up with two
different instances of the same file when making changes.
Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r /etc/profile"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file "/etc/.profile.swp"
to avoid this message.
"/etc/profile" 28 lines, 497 characters
Press ENTER or type command to continue
| 選項 | 適用情境 | 操作 |
|---|---|---|
| 恢復 | 上次編輯有未保存內容,且確認無其他程式正在編輯 | 按 Enter 進入 → 輸入 :recover 或啟動時加 vim -r filename |
| 刪除交換檔 | 確認無重要未存內容、或已手動恢復 | 退出 vi → 終端機執行 rm -f /path/to/.swp |
| 放棄編輯 | 不確定狀態、不想冒險 | 按 q! 強制退出不存檔 |
:q! 強制退出(不存檔)$ rm -f /etc/.profile.swp
# 方法 1:vim 內部恢復
$ vim -r /etc/profile
# 進入後輸入 :recover 確認恢復
# 方法 2:直接用 vim -r 列出所有可恢復檔案
$ vim -r
:w 頻繁存檔習慣set autosave 或外掛自動儲存ServerAliveInterval 避免靜默斷線cp file file.bak