zoukankan      html  css  js  c++  java
  • chattr

    功能说明:chattr命令用于改变文件的扩展属性。与chmod这个命令相比,chmod只是改变文件的读、写、执行权限,更底层的属性控制是由chattr来改变。
     
    语法格式:
    chattr [选项] [模式] [<文件或目录>]
     
    参数选项:
    -R 递归更改目录属性。
    -V 显示命令执行过程。
     
    mode:
    + 增加参数。
    - 移除参数。
    = 更新为指定参数。
    A 不要修改文件的最后访问时间。
    a 只能向文件中添加数据,而不能删除,多用于服务器日志文件安全。
    i 设定文件不能被删除、改名、写入或新增内容。
     
    范例:设置只能往文件里追加内容,但不能删除文件。
    [root@VM_0_15_centos ~]# touch test
    [root@VM_0_15_centos ~]# lsattr test
    -------------e-- test
    [root@VM_0_15_centos ~]# chattr +a test
    [root@VM_0_15_centos ~]# lsattr test
    -----a-------e-- test
    [root@VM_0_15_centos ~]# rm -rf test    # 即使是root用户也不能删除文件
    rm: cannot remove ‘test’: Operation not permitted
    [root@VM_0_15_centos ~]# echo "111" > test
    -bash: test: Operation not permitted
    [root@VM_0_15_centos ~]# echo 111 > test    # 不能清空文件内容
    -bash: test: Operation not permitted
    [root@VM_0_15_centos ~]# cat test
    [root@VM_0_15_centos ~]# echo "222" >> test   # 可以追加文件
    [root@VM_0_15_centos ~]# cat test
    222
    
    
    范例:给文件加锁,使其只能是只读
    [root@VM_0_15_centos ~]# touch file.txt
    [root@VM_0_15_centos ~]# chattr +i file.txt
    [root@VM_0_15_centos ~]# lsattr file.txt
    ----i--------e-- file.txt
    [root@VM_0_15_centos ~]# rm file.txt      # 即使是root用户也不能删除文件
    rm: remove regular empty filefile.txt’? y
    rm: cannot remove ‘file.txt’: Operation not permitted
    [root@VM_0_15_centos ~]# rm -rf file      # 其实没有删除
    [root@VM_0_15_centos ~]# ls -lh file.txt
    -rw-r--r-- 1 root root 0 Jun 23 18:01 file.txt
    [root@VM_0_15_centos ~]# echo 111 >> file.txt  # 不能追加文件
    -bash: file.txt: Permission denied
    [root@VM_0_15_centos ~]# echo 111 > file.txt    # 不能清空文件内容
    -bash: file.txt: Permission denied
    [root@VM_0_15_centos ~]# chattr -i file.txt 
    [root@VM_0_15_centos ~]# rm -rf file.txt 

  • 相关阅读:
    【Linux】在Linux上,使用校园出校器拨号的一个脚本。
    【Android】编译CM10.1遇到的错误解决方案
    【Android】编译CM10遇到的错误解决方案
    【Android】CM在repo中使用local manifest
    一个网站的诞生 MagicDict开发总结1 [首页]
    我记录网站综合系统 1.6发布
    带有ToolTip的ListBox
    字符串的宽度
    .NET开发的文本编辑器,(又发明轮子了,VB代码,不喜误入)
    捕获输入内容
  • 原文地址:https://www.cnblogs.com/l10n/p/9410783.html
Copyright © 2011-2022 走看看