Vim: file for saving root permissions

Source: Internet
Author: User
Tags call shell
Vim saves the root permission file in Linux, and directly uses vim to edit the file in/etc/without sudo. after editing, when you use vim to save the file, you will be prompted that the file cannot be saved, at this time, no permission is found. There are currently several solutions to this problem. 1. vi/et... vim saves the root permission file in Linux, and directly uses vim to edit the file in/etc/without sudo. after editing, when you use vim to save the file, you will be prompted that the file cannot be saved, at this time, no permission is found. There are currently several solutions to this problem. 1. run the command w when saving vi/etc/httpd. conf! 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 ). we strongly recommend this method. However, you must first ensure that the user running vim has the sudo permission. 2. edit the user $ HOME/. vimrc file and rename the hard-to-remember command in the first solution. you can use it directly next time. Vim $ HOME/. vimrc add the following sentence and save it. Command-nargs =? Sudow: w! Sudo tee % when you use vim to edit sudo files in the future, use the Sudow command defined here to save sudo files. 3. First save it to a temporary file, and then use root to copy it to overwrite the file to be edited. A file that may be opened with the user account, vim/etc/httpd. conf. after editing the number in vim, use w/tmp/httpd. conf to save it as a temporary file. 4. use sudo vim directly when using vim. haha, for example, sudo vim/etc/httpd. conf.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.