美文网首页
Vi打开某个文件,保存时提示只读时的简单做法

Vi打开某个文件,保存时提示只读时的简单做法

作者: ForUs | 来源:发表于2015-04-02 20:49 被阅读976次

Vi打开某个文件,保存时提示只读时的简单做法

命令行模式下:
输入
<pre>
:w !sudo tee %
</pre>
再输入
<pre>
:q!
</pre>
现在已经保存并退出了。


用法:
<pre>
:w !sudo tee %
</pre>


:w = Write a file.<br >
!sudo = Call shell sudo command.<br >
tee = The output of the vi/vim write command is redirected using tee.<br >
% = Triggers the use of the current filename.<br >
Simply put, the ‘tee’ command is run as sudo and follows the vi/vim command on the current filename given.

相关文章

网友评论

      本文标题:Vi打开某个文件,保存时提示只读时的简单做法

      本文链接:https://www.haomeiwen.com/subject/gbgoxttx.html