vim儲存root許可權的檔案

來源:互聯網
上載者:User

vim儲存root許可權的檔案 在Linux,沒有sudo 就直接用vim 編輯/etc/內的檔案,等編輯好了之後,使用vim儲存時,得到提示說檔案無法儲存,這時候才發現沒許可權。針對這種問題,目前有如下幾種解決方案。1. vi /etc/httpd.conf 儲存時,用命令:w !sudo tee %    :w - Write a file.    !sudo - Call shell sudo command.    tee - The output of write (vim :w) command is redirected using tee. The % is nothing but current file name i.e. /etc/httpd.conf. In other words tee command is run as root and it takes standard input and write it to a file represented by %. However, this will prompt to reload file again (hit L to load changes in vim itself).強烈推薦這一種用法。不過,首先得保證運行vim的使用者有sudo的許可權。 2.編輯使用者$HOME/.vimrc檔案將第一種方案的比較難記的命令重新命名一下,下次可以直接使用。   vim $HOME/.vimrc  添加如下的一句話,並儲存。   command -nargs=? Sudow :w !sudo tee %   今後用vim編輯時,需要sudo儲存時,直接用此處定義的Sudow命令儲存即可。 3. 先儲存到一個臨時檔案中,然後用root去拷貝它去覆蓋需要編輯的檔案。    可能用user帳號開啟的一個檔案,vim /etc/httpd.conf,然後在vim編輯號後,用:w /tmp/httpd.conf即可儲存為一個臨時檔案。 4. 使用vim之時直接用sudo vim也可以,哈哈,如  sudo vim /etc/httpd.conf 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.