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 

  • 相关阅读:
    连接Excel文件时,未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序
    C# 中LinkLabel的简单使用
    体验安装金蝶K/3 Wise 13.0(图像)
    VS2008让自己掌控的定义编译项目后,自己主动添加到工具箱
    哥哥牟:由于道路的明星莫属,它救了我的女儿!
    【SSH之旅】一步学习的步Struts1相框(三):分析控制Struts1示例
    Ubuntu14.04 工作区设置
    Android定调的发展
    Spark1.0.0 学习路径
    oracle 11g 基于磁盘的备份rman duplicate
  • 原文地址:https://www.cnblogs.com/l10n/p/9410783.html
Copyright © 2011-2022 走看看