Why does a log file have the extension swp? - linux

My log files are generated inside a particular directory on my Linux server. Sometimes when I view the log files inside that directory using ls -lart, I see:
abc.log
.abc.log.swp
Could anybody please explain why the log file has the name .abc.log.swp?

Those are vim "swap" files -- temporary files created by vim while you are editing a file. They are (usually) removed automatically when you exit the editor.

When you edit a file using vi and some other editors, the editor creates a temporary swap file with the .swp extension. If something goes wrong and the editor crashes or the computer dies, the swap file contains your changes so you can revert back to the edited file.
As soon as you close the editor, the swap file should be deleted. If it isn't, and you didn't experience a crash, you can simply remove the swap file.

Related

Vim do not set syntax to file any more after crash?

My System was crashed yesterday, the problem is that syntax is disable and set autoindent is not in use.
Even I remove this file, touch this file again, it remains not right!
Swap files are not meant to edit directly.
Swap files are special files that store pieces of Vim's state, and pieces of the unsaved file, in a Vim-specific format. These are not backup files.
You may be able to use the swap file to recover any edits-in-progress. To do that, simply edit the file you were editing when your system crashed. Vim will detect the swap file and prompt you to recover the file if it is able to do so.
That is, if you haven't invalidated the swap file format attempting to edit it in a misguided attempt to recover your file from it by hand.
Now, Vim does have a separate ability to make real backup files that are copies of your file, whenever it saves. But that doesn't help you from a system crash, that helps you when you mess up your file yourself while you edit, and then save it.
There is also a proposed new feature (in the todo list) for adding a command to recover an entire file from an undo file, if the file itself got deleted somehow, but that's not included in any released Vim yet.

How to restore a modified file in geany on linux?

I have modified a file (personal file) and I saved the modification, now I want to restore the file to its last status before the modification, is it possible? how?
Which distro?
I mean if you are using gedit text editor and you have backup option turned on it then go to the directory of your file and switch to "show hidden files and folders" and there should be a backup. for example if the file name is 1.txt, backup would be 1.txt~. It will contain the stuff before the last save,
As far as I know, Geany does not keep a backup of files by default while saving, so your file changes are probably lost.
Geany however does have a plugin which can do this for you in future. You can enable the Save actions plugin and enable the Backup copy option in it.
If you have just overwritten the file (Ctrl+S) and haven't yet quit Geany, you can just Ctrl+Z to the desired document state and save that file version.
If you have already quit Geany after that and haven't set up back up in Geany before, I am afraid that by means of Geany you cannot restore the file to the previous state.
Read this article about how to set up back up in Geany. Basically you can go to Edit -> Preferences -> Various (read the manual and the link above before changing these preferences) and:
disable use_atomic_file_saving (disabled by default)
enable use_gio_unsafe_file_saving (enabled by default)
enable gio_unsafe_save_backup (disabled by default)
This will always keep the previous version of the file (as a hidden file with ~ attached to its name) next to original.
Or you can install/enable the Save Actions Geany plugin and enable the Auto Save and Backup Copy options to automatically save files at a certain time interval and to keep a copy of previous file versions.

strange behavior saving a file with vim on Windows in a folder that requires elevated permission

I'm editing the apache2.conf configuration file under the 'C:\Program Files...' folder. This folder requires elevated permission ("Start program as administrator") for writing to anywhere on this folder.
Opening the file by mistake with vim without elevation - didn't show any warning. Moreover, I was able to save the file (':wq') just fine without any warning. Opening the file again with vim - showed me the modified file. However - no changes in the behavior of Apache (of course).
Trying to open the file with Notepad - show me the file was not modified.
Then, trying to open the file with vim from an elevated shell - I got the original file (just like notepad), but this time, I was able to edit the file, and save it.
I know have two versions of the file. The real file (shown by notepad, elevated shell, just 'type' and seen by apache httpd), and the file I edited and saved from an unelevated shell - stored somewhere (where???).
This is very uncomfortable, as sometime I open this file by mistake from a regular shell (even just for read).
What is going on? How do I exit this state?
I was hit by a Windows feature called "Virtual Store". Underneath the unaware application (that is, vim in this case), the OS running in compatibility mode will save the files in a folder named "Virtual Store", at this location: C:\Users\<login name>\AppData\Local\VirtualStore\.... The application will not be aware the file went there. Subsequent reads will read from that Virtual Store location.
It seems vim isn't UAC aware and it is running in compatibility mode - which could be fixed, but as for version 7.4 it hasn't.

when apply "chattr +a" on a folder, vim automatically generate numbered file

I have a folder called Text/, and I applied "chattr +a" on that folder as root to prevent deleting files, while allowing creation of new files inside the folder.
I created a new file inside this folder, but every time I changed the content of the file, it automatically generate a numbered file in the same directory, like 5036, 5159
should anyone know what's up? I tried to change the backupdir and dir(for swap file) in vimrc, but still not work.
If you have any idea on this issue, please help me, thanks!
By default Vim makes a backup before overwriting a file, which is deleted after the file is successfully written. As you mentioned on the comments, chattr +a prevents the removal of those bakcup files.
The generation of backup files can be disabled with :set nowritebackup for all files; backupskip option can be used to disable the backup only for folders with restrict attributes. Additional information on :h backup-table.

What can I do with a file open for 'add', if it's submitted via another client

With Perforce, I have the following situation:
Created a new file foo.txt in client client_a, opened it for add
Shelved foo.txt in client_a, unshelved it in client_b
Now foo.txt is open for add in client_b
Submit foo.txt in client_a
Now my question concerns how I can cleanup foo.txt in client_b. Maybe it has a one line change from the depot version that I'd like to keep. Ideally I'd like to do a resolve operation against the newly checked in file, but I'm not allowed to do this because it's open for add.
Now I have this file foo.txt#1 - add change default in my client.
I can't reopen the file ('nothing changed'), I can't diff it vs the depot ('file not open for edit'), I can't resolve it against the depot ('no files to resolve'), I can't open it for edit ('can't edit, already opened for add').
Is there any way to make perforce reopen this as edit instead of add? I know I can copy it to a temp file, revert, reopen for add, and then recopy the temp file back over, but this seems rather unelegant. Is there any command that can do what I want, or is there a good reason I'm not seeing why it's disallowed?
Only slightly more elegant than the comment in your last paragraph, but you should be able to:
Revert foo.txt in client_b. Since it was marked for add the file will remain on the disk with no changes
Sync foo.txt with -k. This makes the server think you have the latest revision without modifying your local file.
Check out foo.txt for edit. Diff'ing against the have revision should show the changes.
Submit your changes.

Resources