萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Linux 教學

Linux vi 編輯器啟動提示 E325: ATTENTION 交換檔衝突解決:刪除 .swp 檔案恢復正常

使用 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! 強制退出不存檔

三、標準解決步驟(最常用:刪除 .swp)

  1. 按 Enter 進入 vi
  2. 輸入 :q! 強制退出(不存檔)
  3. 終端機刪除交換檔:
    $ rm -f /etc/.profile.swp
  4. 再次編輯同檔案,警告消失

四、進階:恢復未存內容

# 方法 1:vim 內部恢復
$ vim -r /etc/profile
# 進入後輸入 :recover 確認恢復

# 方法 2:直接用 vim -r 列出所有可恢復檔案
$ vim -r

五、預防建議

  • 養成 :w 頻繁存檔習慣
  • 使用 set autosave 或外掛自動儲存
  • SSH 會話建議啟用 ServerAliveInterval 避免靜默斷線
  • 重要檔案編輯前先備份 cp file file.bak
copyright © 萬盛學電腦網 all rights reserved