,

What is .swp file extension in linux?

Posted by

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Under Linux, swap files made with the vi or vim text editors are identified by the .swp extension. In order to recover work in the event of a crash or unintentional exit, these files are used to retain the state of a file that is being modified.

Key Points About .swp Files:

  • Creation: A swap file is generated to temporarily store changes when you open a file in vi or vim.
  • Location: The swap file is usually named after the original file, with .swp attached, and kept in the same directory as the original file.
  • Recovery: You can restore your modifications using the swap file in the event that vim fails or terminates abruptly.
  • Deletion: When you correctly leave vim, swap files are often automatically erased. But if you notice .swp files remaining, it may mean that vim was not closed correctly.

Managing .swp Files:

Listing Swap Files: You may use the ls command with a wildcard to list every swap file in a directory.

ls -l *.swp

File Recovery: Open the file in vim to begin file recovery using its swap file.

vim -r filename

Delete a Swap File: You may use the rm command to remove a swap file if you are certain you don’t need it.

rm filename.swp

Avoiding the Creation of Swap Files: You may instruct vim to avoid creating swap files by including the following line in your .vimrc file

set noswapfile

Example Scenario:

A swap file named.example.txt.swp will be produced in the same directory if you are using vim to edit a file called example.txt. The swap file is not deleted if vim crashes or if you close the terminal without fully quitting vim. Vim will offer you to use the swap file to recover example.txt the next time you access it.

When using vim or vi, knowing how .swp files operate can help you organize and restore your work more efficiently.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x