Special Functions of vim (changing user identities)

Source: Internet
Author: User
Special Functions of vim (changing user identities)-Linux general technology-Linux technology and application information. The following is a detailed description. [I = s] This post was last edited by Acacia love

I read the fedora file today? Cheng ^ Cheng ??? This post is an experiment. The results show the special functions of vim, which can be used as chown in special environments.

Let's talk about vim functions first. You can modify files and read-only files.
For example, the configuration file/boot/grub. cfg of grub2 is read-only. To use another editor, you must modify the permissions before editing. But use vim to modify it: w! You can force write.

My system is debian, two users, respectively.

First, create a temporary directory and set the permission to 777, that is, all users can read and write, and then create a file.

Hcc @ debian:/tmp $ cd/tmp/
Hcc @ debian:/tmp $ mkdir lx
Hcc @ debian:/tmp $ chmod 777 lx/
Hcc @ debian:/tmp $ cd lx/
Hcc @ debian:/tmp/lx $ touch 1 2 3
Hcc @ debian:/tmp/lx $ ls-l
Total 0
-Rw-r -- 1 HSCC 0 10-23 21:41 1
-Rw-r -- 1 HSCC 0 10-23 21:41 2
-Rw-r -- 1 HSCC 0 10-23 21:41 3

Hcc @ debian:/tmp/lx $ su sun
Password:
Sun @ debian:/tmp/lx $ vim 1
When editing
W10: Warning: Changing a readonly file Warning: Changing read-only files
As a result, w cannot be written. So we can use: wq! Force write and exit (without modifying the content directly: wq! Also ).
Result
Sun @ debian:/tmp/lx $ ls-l
Total 4
-Rw-r -- 1 sun 40 10-23 21:46 1
-Rw-r -- 1 HSCC 0 10-23 21:41 2
-Rw-r -- 1 HSCC 0 10-23 21:41 3
Sun @ debian:/tmp/lx $
As you can see, the owner identity of the file has changed.

However, you cannot use chown, chgrp, or chmod to modify your identity and permissions as sun. You can only delete them using rm.

Sun @ debian:/tmp/lx $ chmod 777 2
Chmod: Change "2" permission: operation not allowed
Sun @ debian:/tmp/lx $ rm 3
Rm: Do you want to delete the "3" common empty file with write protection "? Y
Sun @ debian:/tmp/lx $ ls-l
Total 4
-Rw-r -- 1 sun 40 10-23 21:46 1
-Rw-r -- 1 HSCC 0 10-23 21:41 2
Sun @ debian:/tmp/lx $

Previously, only when the current user has the right to change the File Permission, vim can forcibly write a read-only file, and can still modify the file identity (e: e2s.

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.