hi i am sachin and new user to Linux i was trying my hand on permissions for that i create structure like this ~/sachin/d/text.text (IN MY HOME DIRECTORY )and i gave only execute permission on directory 'd' and then try to edit text.text file in vi. vi opens the file and edit the file and save also. Normally when there is write permission on directory vi change the inode of file ie it replace the file but in this case it does not do that it update the contain of the file instead and it crate swap file in /var/tmp edit it there then make the change in text from that where as office.org every time follows the second step of vi it updates the contain of file..........................
NOW MY QUESTION IS .........WHY VI BEHAVES LIKE THIS ????
AND WHICH METHOD IS EFFICIENT AND HOW.....so far ACCORDING TO ME I GUESS VI INOSDE CHANGING METHOD IS FAST I KNOW THAT VI DONT HAVE PERMISSION TO Replace FILE IN THAT DIRECTORY THATS WHY BUT WHY IT DONT BEHAVE LIKE OFFICE.ORG EVERY TIME OR MAY BE VI IS SMARTER THAN OFFICE.ORG
I think my post was not very clear. Let me restate my question:
Case 1 - All permissions are set (rwx) for owner on parent directory. (I am the owner.)
$ ls -ld dir
drwxrwxr-x 2 sachin sachin 4096 Mar 7 13:42 dir
In this case when editing the file "text.text", vim creates a temporary swap file in that directory. When the file is saved, the swap file is deleted and the inode number of "text.text" changes (it is different from the inode number of the original file and also the swap file).
Case 2 - Write permission is removed from parent directory
$ ls -ld dir
dr-xr-xr-x 2 sachin sachin 4096 Mar 7 13:42 dir
In this case when editing the file "text.text", vim creates a temporary swap file in /var/tmp. After saving the file, its inode does not change.
This means that in case 2, vim is updating the contents of the file in-place. I have found that OpenOffice.org also updates the contents in-place, irrespective of the parent directory permissions.
I wish to know why does vim create a new file in case 1. Wouldn't it be a costly operation, especially in case of large files? In short, which method is more efficient to implement for any file editor?
Please note that in all cases, all permissions are set on the file itself (i.e. text.text). I am just manipulating the permissions of the parent directory.
thanks in advance