私はこれが何を意味するのか理解する力何かしてみてください。
これはモード$ vim -R file
に入り、read-only
予防モードとしてのみ使用されます。
-R Readonly mode. The 'readonly' option will be set for all the
files being edited. You can still edit the buffer, but will
be prevented from accidentally overwriting a file. If you
forgot that you are in View mode and did make some changes,
you can overwrite a file by adding an exclamation mark to
the Ex command, as in ":w!". The 'readonly' option can be
reset with ":set noro" (see the options chapter, |options|).
Subsequent edits will not be done in readonly mode. Calling
the executable "view" has the same effect as the -R argument.
The 'updatecount' option will be set to 10000, meaning that
the swap file will not be updated automatically very often.
しかし、私がまだ理解していないのは、root
ファイルの所有者がユーザーであっても権限をスキップする指示を発行し、所有者とグループを変更する理由です。
ベストアンサー1
!
一般的に「force」から期待することを意味しますが、特定のコマンドの意味はコマンドによって異なります。w!
何らかの理由でVimがファイルに書き込めない場合、Vimは現在のバッファの内容を使用して新しいファイルを削除して生成しようとします。
次の例を検討してください(inode番号を観察)。
$ touch foo
$ chmod -w foo
$ stat foo
File: ‘foo’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 22h/34d Inode: 10396141 Links: 1
Access: (0444/-r--r--r--) Uid: ( 1000/ muru) Gid: ( 1000/ muru)
Access: 2015-09-10 00:24:28.259290486 +0530
Modify: 2015-09-10 00:24:28.259290486 +0530
Change: 2015-09-10 00:24:30.771263735 +0530
Birth: -
$ vim -c 'r!date' -c 'wq!' foo
$ stat foo
File: ‘foo’
Size: 30 Blocks: 8 IO Block: 4096 regular file
Device: 22h/34d Inode: 10396151 Links: 1
Access: (0444/-r--r--r--) Uid: ( 1000/ muru) Gid: ( 1000/ muru)
Access: 2015-09-10 00:24:37.727189657 +0530
Modify: 2015-09-10 00:24:37.731189614 +0530
Change: 2015-09-10 00:24:37.763189273 +0530
Birth: -
$ cat foo
Thu Sep 10 00:24:37 IST 2015
それで主人とグループが変わるんです。権限が予約されました -:h write-permissions
:
write-permissions
When writing a new file the permissions are read-write. For unix the mask is
0666 with additionally umask applied. When writing a file that was read Vim
will preserve the permissions, but clear the s-bit.
Vimが書き込みを拒否するには、次を参照してください:h write-readonly
。
write-readonly
When the 'cpoptions' option contains 'W', Vim will refuse to overwrite a
readonly file. When 'W' is not present, ":w!" will overwrite a readonly file,
if the system allows it (the directory must be writable).
「ディレクトリは書き込み可能でなければなりません」と書かれています。書き込み可能なディレクトリがないと、Vimはファイルを削除したり新しいファイルを作成したりできないためです。