LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-05-2009, 10:44 PM   #1
sachin.s.puri
LQ Newbie
 
Registered: Mar 2009
Posts: 5

Rep: Reputation: 0
why vi beahave like this


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


------------------------------------------------------------------
EDIT:

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

Last edited by sachin.s.puri; 03-07-2009 at 02:25 AM. Reason: Clarification of question
 
Old 03-06-2009, 04:07 PM   #2
T74marcell
Member
 
Registered: Mar 2009
Posts: 102

Rep: Reputation: 18
Sorry, but it's extremely difficult to figure out your posting. From what I sorted out of it, I would say that you should give write permissions to your own stuff at least for yourself. Without write permissions the best thing vi can do is to work inside /tmp, which is writeable.

I really don't think that inode manipulation and a lot of wizard stuff is going on behind the scenes. It's also not about one tool being smarter than the other.

Arch Linux

Last edited by T74marcell; 03-14-2009 at 01:03 AM.
 
Old 03-06-2009, 06:48 PM   #3
GazL
Senior Member
 
Registered: May 2008
Posts: 3,426

Rep: Reputation: 937Reputation: 937Reputation: 937Reputation: 937Reputation: 937Reputation: 937Reputation: 937Reputation: 937
You're quite right. editing an existing file with vim creates a new file (with a new inode number unless you don't have write access to the directory, in which case it seems to update the file in-place using the existing inode. Do the same thing with elvis and it appears to retain the old inode regardless of whether you have write access to the directory or not.

So it appears that the implementation of vi that you use is significant. On a full install of Slackware the default vi is 'elvis', which is the one I normally use. I suspect the majority of distributions link vi -> vim. Why vim works the way it does, I have no idea, but if you don't like it, you could always use elvis instead.
 
  


Reply

Tags
editor, file, inode, swap, vi


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT -5. The time now is 06:59 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration