Why is editing a file by renaming the new one safer?
Hello:
I've been reading about ways to edit files from the command line, and I've found two websites which state that the following is the safest way to edit a file:
That is, renaming the newer file to the previous one. This is what the websites I mentioned state:
Quote:
Before you start, be warned that editing files is a really bad idea. The preferred way to modify a file is to create a new file within the same file system, write the modified content into it, and then mv it to the original name. This is the only way to prevent data loss in the event of a crash while writing. However, using a temp file and mv means that you break hardlinks to the file (unavoidably), that you would convert a symlink to hard file, and that you may need to take extra steps to transfer the ownership and permissions (and possible other metadata) of the original file to the new file. Some people prefer to roll the dice and accept the tiny possibility of data loss versus the greater possibility of hardlink loss and the inconvenience of chown/chmod (and potentially setfattr, setfacl, chattr...).
So, generally speaking, to accomplish almost any editing task on a file, temporary files should be used. Sure, if the file is big, creating a temporary file becomes more and more inefficient, and requires that an amount of available free space roughly the same size of the original file is available. Nonetheless, it's by far the only right and sane way to do the job. Modern machines should have no disk space problems.
[...]
In any case, for our purposes the important thing to remember of these methods is that the old file stays around (whether under its original name or a different one) until the new one has been completely written, so errors can be detected and the old file rolled back. This makes them the preferred method for changing a file safely.
What I don't understand is: what makes it safer? Why is it safer in the case the machine stops unexpectedly once the file was renamed? What's the logic behind this?
hi! I am a newbee. I would really appreciate if you can answer the following question:
I have a huge data file, 214MB with several coloumns. I need to delete the very last line of the file. Everything I know takes a lot of time to do it ( because I have to open the file in an editor or run a... (3 Replies)
For those with the iPhones here might read up how to wipe your personal data off the phone before reselling or trade-in. ;)
source: Nuclear Elephant: iPhone Wipe
June 1, 2008: Making your iPhone Safe for Resale
Since my posts regarding the iPhone restore mode being insufficient for wiping... (0 Replies)
I know that you already know the answer to the question. It just springed in my mind after what happened yesterday. I was getting some books off of Amazon.com, since they are cheeper than bookstore, and my mother said something that made me laugh 'till I couldn't breathe. I have a Debian Lenny... (12 Replies)
Hi all
I need to change my current metaset setname from lh-rms02ds to lh-lgwrms01ds. Is it possible ?? I know within veritas I do a vxedit, is there a way in SVM ?
I notice theres a metarename, but this is for the metadevice level.
Any tips ? help ?? Or do I need to delete /... (2 Replies)
Hi,
I am having a file which is fix length and comma seperated. And I want to replace values for one column.
I am reading file line by line in variable $LINE and then replacing the string.
Problem is after changing value and writing new file temp5.txt, formating of original file is getting... (8 Replies)
I have a text file that has data like:
Data "12345#22"
Fred
ID 12345
Age 45
Wilma
Dino
Data "123#22"
Tarzan
ID 123
Age 33
Jane
I need to figure out a way of adding 1,000,000 to the specific lines (always same format) in the file, so it becomes:
Data "1012345#22"
Fred
ID... (16 Replies)
I have a file which has 10 million records in it. When am trying to edit the file with vi, the following error occurs:
~
~
~
~
~
~
~
~
"file1" Value too large for defined data type
Is there any way that I can edit this file without using vi? Any help would be really appreciated.... (8 Replies)
Hi All,
Please tell me the use of # /Unix.org file it has reserved a huge disk space, I want to know is it safer to truncate or delete.
Thanks - Rukshan.:) (1 Reply)
Dear Guru's
I'm using Putty and want to edit a file. I know we generally use vi editor to do it. As I'm not good in using vi editor, I want to convert the vi into something like text pad. Is there any option in Putty to do the same ? Thanks for your response.
Srini (6 Replies)
Discussion started by: thummi9090
6 Replies
LEARN ABOUT MOJAVE
mailcap.order
MAILCAP.ORDER(5) Order Mailcap Entries MAILCAP.ORDER(5)NAME
/etc/mailcap.order - the mailcap ordering specifications
DESCRIPTION
The order of entries in the /etc/mailcap file can be altered by editing the /etc/mailcap.order file. Each line of that file specifies a
package and an optional mime type. Mailcap entries that match will be placed in the order of this file. Entries that don't match will be
placed later.
Example
mime-support:*/*
gv:application/postscript
netscape:text/html
less:text/*
emacs:text/*
The above would make any entries provided by the mime-support package (as found in the /usr/lib/mime/packages directory) take priority over
everything else. The gv package will be used over anything else when it comes to postscript documents. Netscape will be used for any html
documents and less will be used for any remaining text documents. However, since neither netscape or less provide for editing documents,
any edit or compose actions will fall through to the emacs rules.
After modifying this file, be sure to run /usr/sbin/update-mime (as root) to propagate the changes into the /etc/mailcap file.
Remember that this files takes package names and not executable names. If you want to define rules that reference specific programs, the
best way is to include them in ~/.mailcap or the user section of the /etc/mailcap file.
LIMITATIONS
There is currently no way to break out a certain type from a wildcard rule. If, for example, both xv and gimp were to specify "image/*"
rules, it isn't possible to use xv for gif images but use gimp for jpeg images.
Also, I would like to add the ability to specify certain actions in the rules. For example, if netscape were to have an edit rule but I
wanted to use emacs for editing/creating html documents, I could place a line like
emacs:text/* action=edit|compose
before the netscape entry. The update-mime program would then spit out entries such that netscape view rule comes before the emacs view
rule but have the netscape edit rule comes after the emacs edit rule.
SEE ALSO mailcap(5)run-mailcap(1)update-mime(8)AUTHOR
The mailcap.order specification was written by Brian White <bcwhite@pobox.com>
Debian Project 16th Aug 1998 MAILCAP.ORDER(5)