Linux system O & M skills

Source: Internet
Author: User

We have the requirement that the next file in the Linux system cannot be modified, deleted, or added only. We can use the chattr command.

[Root @ serv01 test] # cat note.txt
1. Do not be late
2. Do not leave early
3. Do not smoke
[Root @ serv01 test] # chattr + I note.txt

# Cannot be edited by any root user
[Root @ serv01 test] # vim note.txt
[Root @ serv01 test] # cat note.txt
1. Do not be late
2. Do not leave early
3. Do not smoke

# Root users cannot delete modifications
[Root @ serv01 test] # rm-f note.txt
Rm: cannot remove 'note.txt ': Operation not permitted
[Root @ serv01 test] # echo "this is test"> note.txt
-Bash: note.txt: Permission denied

# Ll. You cannot view the file attributes. You need to use lsattr to view the attributes.
[Root @ serv01 test] # ll note.txt
-Rw-r --. 1 root 45 Sep 21 17:46 note.txt
[Root @ serv01 test] # lsattr note.txt
---- I -------- e-note.txt

# It is a relative concept that root users cannot modify. root users can modify the attributes of files.
[Root @ serv01 test] # chattr-I note.txt
[Root @ serv01 test] # lsattr note.txt
------------- E-note.txt
[Root @ serv01 test] # vim note.txt
[Root @ serv01 test] # cat note.txt
1. Do not be late
2. Do not leave early
3. Do not smoke
4. Don't come to work

# Message board: What You Said cannot be deleted
[Root @ serv01 test] # vim note.txt
[Root @ serv01 test] # cat note.txt
1. Do not be late
2. Do not leave early
3. Do not smoke
4. Don't come to work
Hello
[Root @ serv01 test] # chattr + a note.txt
[Root @ serv01 test] # lsattr note.txt
----- A ------- e-note.txt
[Root @ serv01 test] # vim note.txt
[Root @ serv01 test] # ls
Note.txt ~ Note. txy ~ Note. txz ~
# Delete, no permission found
[Root @ serv01 test] # rm-rf *
Rm: remove regular file 'note.txt '? Y
Rm: cannot remove 'note.txt ': Operation not permitted
[Root @ serv01 test] # ls
Note.txt upload
[Root @ serv01 test] # echo "hello world"> note.txt
-Bash: note.txt: Operation not permitted
# You can only append the content.
[Root @ serv01 test] # echo "hello world"> note.txt
[Root @ serv01 test] # cat note.txt
1. Do not be late
2. Do not leave early
3. Do not smoke
4. Don't come to work
Hello
Hello world

[Root @ serv01 test] # chattr-a note.txt
[Root @ serv01 test] # lsattr note.txt
------------- E-note.txt

 

  • 1
  • 2
  • Next Page
[Content navigation]
Page 1: chattr and lsattr commands Page 6: motd and issue files

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.