Linux Vi/vim Edit file without permission to save how to solve

Source: Internet
Author: User

In a Linux environment, if you use the Vi/vim command to edit files without modifying permissions directly, the user will be prompted to save when saved, and the general solution is to turn off the file again with sudo permission to open the file Edit and save (if the user has sudo permission). In fact, in the Vi/vim mode through a number of simple commands, you can not close the current file to achieve the purpose of saving the file:

Enter command:%! sudo tee% >/dev/null
Enter sudo password by prompt
Enter "L" (Load File)
Input: Q command exit

About "%! sudo tee% >/dev/null "This order is described as follows:

% #VI/vim edited file contents
! #管道
sudo #以root权限操作
Tee #将标准输入 (that is, the contents of the currently edited file coming through the pipe) to the standard output, while writing to the specified file (that is, Vi/vim the currently edited file)
% #VI files edited by/vim

>/dev/null #将标准输出重定向到/dev/null (no output display)

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.