Problem with permissions and vi

Mel fbsd.questions at rachie.is-a-geek.net
Tue Dec 2 02:06:26 PST 2008


On Tuesday 02 December 2008 10:32:48 Adam Zaleski wrote:
> Hello,
>
> I have a problem setting up some permissions to file
> and editing this file with vi.. I have two different
> examples to show you what I mean... First one:
>
> [netlest at unixlab ~]$ echo "some text" > some_file.txt
> [netlest at unixlab ~]$ chmod 000 some_file.txt
> [netlest at unixlab ~]$ ls -l some_file.txt
> ----------  1 netlest  staff  10  2 gru 09:55 some_file.txt
> [netlest at unixlab ~]$ echo "some other text" >> some_file.txt
> -bash: some_file.txt: Permission denied
> [netlest at unixlab ~]$ cat some_file.txt
> cat: some_file.txt: Permission denied
> [netlest at unixlab ~]$ chmod 600 some_file.txt
> [netlest at unixlab ~]$ cat some_file.txt
> some text
> [netlest at unixlab ~]$
>
>
> Everythink was ok...
>
> And now.. another one
> [netlest at unixlab ~]$ echo "some text" > some_file.txt
> [netlest at unixlab ~]$ chmod 000 some_file.txt
> [netlest at unixlab ~]$ ls -l some_file.txt
> ----------  1 netlest  staff  10  2 gru 09:55 some_file.txt
> [netlest at unixlab ~]$ vi some_file.txt
>
> Now ignore warnings with permission denied showing in vim..
> and put some text into the some_file.txt and then :wq!
>
> [netlest at unixlab ~]$ ls -l some_file.txt
> ----------  1 netlest  staff  33  2 gru 10:23 some_file.txt
> [netlest at unixlab ~/t]$ cat some_file.txt
> cat: some_file.txt: Permission denied
> [netlest at unixlab ~/t]$ chmod 600 some_file.txt
> [netlest at unixlab ~/t]$ cat some_file.txt
> aasda
> sd
> a some texs
> asdas
> d
> as
> [netlest at unixlab ~/t]$
>
>
> Why I am able to put some text into some_file.txt with
> chmod 000 using vi editor and why i can not do the same
> using echo???

Because you have write access on the directory and :wq with an exclamation 
mark !, forces the write, which in actuality removes the file and writes the 
editor contents to a new file, then restores permissions.

-- 
Mel

Problem with today's modular software: they start with the modules
    and never get to the software part.


More information about the freebsd-questions mailing list