728x90

Linux vi을 통하여 작업을 하던 중 간혹 마주치는 문제입니다.

편집하려고 해당 파일을 열었는데 떡하니, 나온다면 처음 접해본 사람이라면 누구나? 어 이게 뭐지... 반응이 나올 것 입니다.

그래서 오늘은 vi swap 원인과 해결 방법에 대해 알아보겠습니다.



E325: ATTENTION

Found a swap file by the name ".home.php.swp"

          owned by: cellgentek   dated: Mon Mar 23 10:06:05 2020

         file name: /var/www/html/test/home.php

          modified: YES

         user name: ****   host name: ****

        process ID: ****

While opening file "home.php"

             dated: Mon Mar dd hh:mm:ss yyyy


(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 home.php"

    to recover the changes (see ":help recovery").

    If you did this already, delete the swap file ".home.php.swp"

    to avoid this message.


Swap file ".home.php.swp" already exists!

[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort: 


1. 원인

Found a swap file by the name ".home.php.swp"의 문구를 보면 왜 나타났는지 알 수 있습니다.

.swp 확장자를 가지고 있는 스왑 파일이 발생하여, 이 문제가 생겼다는 것을 알 수 있습니다.

그럼 .swp 확장자 어떤 것인가?

vi 편집기 사용하는 동안 비정상적 종료(네트워크 끊김, 강제 종료 등)가 발생한다면, 임시로 파일을 저장하기 위해 사용됩니다.

즉. 편집기를 사용하면, 스왑 파일은 숨김 파일로 만들어 임시 파일로 저장합니다.

그래서 정상적으로 vi 편집기를 사용한다면, .swp 확장자는 자동 삭제합니다.

이 경우는 정상적으로 저장이 안되었기에, .swp 확장자를 통하여 사용자에게 알려줍니다.


2. 해결 방법

1) .swp 확장자 존재를 확인합니다.

2) .swp 확장자는 아까 말한듯이 숨김 파일이므로, ls -all로 확인을 합니다.

3) 다른 프로세스가 사용 중일 수 도 있기에, 다른 프로세스가 작업 중인지 확인합니다.

  ▶ ps -ef | grep 해당 (파일 이름)home.php

  사용 없을 경우 : pts/0    00:00:00 grep --color=auto home.php

4) 사용 유/무 확인 했으므로, vi -r (파일 이름)home.php 으로 복구를 진행합니다.


Using swap file ".home.php.swp"

Original file "/var/www/html/test/home.php"

E308: Warning: Original file may have been changed

Recovery completed. You should check if everything is OK.

(You might want to write out this file under another name

and run diff with the original file to check for changes)

You may want to delete the .swp file now.


Press ENTER or type command to continue 

5) Enter를 하여 파일로 들어갑니다.

6) 해당 파일을 :wq 하여 저장 후 빠져나옵니다.

7) rm (파일 이름).home.php.swp를 하여 삭제를 합니다.


이렇게 하시면, Vi swap는 해결 되었습니다.




728x90

+ Recent posts