使用 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.

| 欄位 | 含義 |
|---|---|
swap file | 交換檔路徑 (.swp),記錄編輯緩衝區 |
owned by / dated | 建立交換檔的用戶與時間 |
modified: YES | 交換檔包含未寫入磁碟的變更 |
process ID | 建立交換檔的 vim 進程 PID (可用 ps -p PID 檢查是否仍在運行) |
:recover 按 Enter.swp 恢復緩衝區內容:w 存檔rm /etc/.profile.swp或單指令恢復:vim -r /etc/profile
:q! 強制退出不存檔rm /etc/.profile.swpvi /etc/profile 正常編輯:recover 恢復內容:w /etc/profile.recovered 另存:q! 退出diff /etc/profile /etc/profile.recovered| 情況 | 建議策略 |
|---|---|
| 單人使用、確認無其他編輯進程 | A (恢復) |
多人協作、或 ps -p PID 顯示進程仍在運行 | C (另存對比) 或聯繫對方 |
| 不重要檔案、寧可丟失未存變更 | B (放棄) |
| 系統剛重啟、先前編輯確實中斷 | A (恢復) |
./.file.swp) 或 /tmp, /var/tmp, ~/set directory=~/vimswap// (雙斜線啟用目錄層級隔離)set noswapfile (不建議,喪失崩潰恢復能力)set updatetime=3000 (毫秒,預設 4000):w 頻繁存檔tmux/screen 保持會話,避免 SSH 斷線丟失編輯狀態cp /etc/profile /etc/profile.bakset autoread 外部修改自動重載E325 不是錯誤,是 vim 的保護機制。核心流程:確認衝突來源 → 選擇恢復/放棄/對比 → 刪除 .swp → 繼續編輯。養成 tmux + 頻繁存檔習慣,可將遇到此警告的機率降至最低。
Linux 多網卡綁定 (Bonding/Teaming) 完整配置指南:mode=1 主備模式實戰
CentOS 6.4 部署 GlusterFS 分布式存儲:從安裝到多節點複製卷實戰
Linux 自動生成 MAC 地址:Shell、Python、Perl、Ruby 四語言實現與效能對比
Linux 安装配置 Fail2Ban 防暴力破解:SSH 保护、邮件通知与日志轮转
Linux 管道機制深度解析:pipe() 系統呼叫、無名/命名管道與實戰範例
Linux sshd 啟動報錯 Could not load host key 解決:重新產生 ED25519 主機金鑰