我们使用 linux 文件系统定义的文件属性,能够对linux文件系统进行进一步保护;从而给文件 赋予一些额外的限制;在有些情况下,能够对我们的系统提供保护;

该命令特定用于 linux  extended filesystem (ext2, ext3, ext4),是e2fsprogs 工具的一部分;而e2fsprogs 工具包,包含了创建,检查和维护ext2/3/4-based 文件系统的工具。其也包含badblocks等用于检查文件系统坏块的工具。

chattr命令用来改变文件属性。这项指令可改变存放在ext2文件系统上的文件或目录属性,这些属性共有以下8种模式:详细作用,可以查看man手册;注意该属性不是linux文件系统扩展属性。

a:让文件或目录仅供附加用途;
b:不更新文件或目录的最后存取时间;
c:将文件或目录压缩后存放;
d:将文件或目录排除在倾倒操作之外;
i:不得任意更动文件或目录;
s:保密性删除文件或目录;
S:即时更新文件或目录;
u:预防意外删除。
 lsattr - list file attributes on a Linux second extended file system

比如你可以给 /etc/passwd 文件进行修改,这样就是连root用户都不能更改它的代码;

File attributes on a Linux file system according to the chattr(1) Linux man page (该表格转载自维基百科)
Attribute lsattr flag chattr option Semantics and rationale
Compressed dirty file Z (unavailable)
  • The Z attribute is used by the experimental compression patches to indicate a compressed file is "dirty".
Compression raw access X (unavailable)
  • The X attribute is used by the experimental compression patches to indicate that a raw contents of a compressed file can be accessed directly.
Undeletable u +u to set
-u to clear[note 2]
  • When a file with the u attribute set is deleted, its contents are saved.
  • This allows the user to ask for its undeletion.
Top of directory hierarchy T +T to set
-T to clear
  • A directory with the T attribute will be deemed to be the top of directory hierarchies for the purposes of the Orlov block allocator.
  • This is a hint to the block allocator used by ext3 and ext4 that the subdirectories under this directory are not related, and thus should be spread apart for allocation purposes.
  • For example: it is a very good idea to set the T attribute on the /home directory, so that /home/john and /home/mary are placed into separate block groups.
  • For directories where this attribute is not set, the Orlov block allocator will try to group subdirectories closer together where possible.
No tail-merging t +t to set
-t to clear
  • For those filesystems that support tail-merging, a file with the t attribute will not have a partial block fragment at the end of the file merged with other files.
  • This is necessary for applications such as LILO, which reads the filesystem directly and doesn't understand tail-merged files.
Synchronous updates S +S to set
-S to clear
  • When a file with the S attribute set is modified, the changes are written synchronously on the disk; this is equivalent to the 'sync' mount option applied to a subset of the files.
  • This is equivalent to the sync mount option, applied to a subset of the files.
Secure deletion s +s to set
-s to clear[note 2][note 5]
Data journaling j +j to set
-j to clear[note 4]
  • A file with the j attribute has all of its data written to the ext3 journal before being written to the file itself, if the filesystem is mounted with the "data=ordered" or "data=writeback" options.
  • When the filesystem is mounted with the "data=journal" option all file data is already journaled, so this attribute has no effect.
Indexed directory I (unavailable)
  • The I attribute is used by the htree program code to indicate that a directory is being indexed using hashed trees.
Immutable i +i to set
-i to clear[note 1]
  • A file with the i attribute cannot be modified.
  • It cannot be deleted or renamed, no link can be created to this file and no data can be written to the file.
  • When set, prevents, even the superuser, from erasing or changing the contents of the file.
Huge file h (unavailable)
  • The h attribute indicates the file is storing its blocks in units of the filesystem blocksize instead of in units of sectors.
  • It means that the file is, or at one time was, larger than 2TB.
Compression error E (unavailable)
  • The E attribute is used by the experimental compression patches to indicate that a compressed file has a compression error.
Extent format e (unavailable)
  • The e attribute indicates that the file is using extents for mapping the blocks on disk.
Synchronous directory updates D +D to set
-D to clear
  • When a directory with the D attribute set is modified, the changes are written synchronously on the disk
  • This is equivalent to the dirsync mount option, applied to a subset of the files.
No dump d +d to set
-d to clear
  • A file with the d attribute set is not candidate for backup when the dump program is run.
No Copy-on-Write (CoW) C +C to set
-C to clear[note 3]
  • A file with the C attribute will not be subject to Copy-on-Write updates.
  • Updates to these files may not be subject to atomic snapshots, and may lack some reliability information on some filesystems and kernels.
Compressed c +c to set
-c to clear[note 2]
  • A file with the c attribute set is automatically compressed on the disk by the kernel.
  • A read from this file returns uncompressed data.
  • A write to this file compresses data before storing them on the disk.
No atime updates A +A to set
-A to clear
  • When a file with the A attribute set is accessed, its atime record is not modified.
  • This avoids a certain amount of disk I/O operations.
Append only a +a to set
-a to clear[note 1]
  • A file with the a attribute set can only be open in append mode for writing.
Version / generation number -v -v version
  • File's version/generation number.

参考链接:

https://en.wikipedia.org/wiki/Chattr (上述表格来自于此)

http://c.biancheng.net/view/874.html

https://www.runoob.com/linux/linux-comm-chattr.html

https://www.runoob.com/linux/linux-comm-lsattr.html

https://www.cnblogs.com/ftl1012/p/chattr.html

保持更新,更多内容请关注 cnblogs.com/xuyaowen; 获取更多内容;

关于文件系统扩展属性内容,请参考:Linux 文件系统扩展属性

chattr lsattr linux file system attributes - linux 文件系统扩展属性的更多相关文章

  1. Linux 文件系统扩展属性【转】

    转自:https://blog.csdn.net/ganggexiongqi/article/details/7661024 扩展属性(xattrs)提供了一个机制用来将<键/值>对永久地 ...

  2. linux中suid/sgid/sticky及扩展属性(attr)

    suid只适用于命令文件.(如/usr/bin/passwd) 当命令文件上有suid权限时,则操作用户的权限变成属主权限.命令文件上无suid权限则操作用户的权限不变. 查看suid权限: [roo ...

  3. 磁盘、分区及Linux文件系统 [Disk, Partition, Linux File System]

    1.磁盘基础知识 1.1 物理结构 硬盘的物理结构一般由磁头与碟片.电动机.主控芯片与排线等部件组成:当主电动机带动碟片旋转时,副电动机带动一组(磁头)到相对应的碟片上并确定读取正面还是反面的碟面,磁 ...

  4. Linux File System Change Monitoring Technology、Notifier Technology

    catalog . 为什么要监控文件系统 : hotplug . udev . fanotify(fscking all notification system) . inotify . code e ...

  5. Linux File System

    目录 . Linux文件系统简介 . 通用文件模型 . VFS相关数据结构 . 处理VFS对象 . 标准函数 1. Linux文件系统简介 Linux系统由数以万计的文件组成,其数据存储在硬盘或者其他 ...

  6. changing permissions of Read-only file system in linux

      up vote 2 down vote favorite 1 i use this command to make a bootable flash disk of linux mint sudo ...

  7. key directories in the linux file system

    Key directories in the file system: */: Root directory (base of file system) /bin: Executable progra ...

  8. linux文件系统扩展属性

    翻译自man手册,水平有限,有错还望不吝指出.... 扩展属性是与文件和目录相关的name:value对,用来提供文件系统的一些附加功能,例如ACL.对文件或是目录拥有读权限的用户可以看到其扩展属性. ...

  9. File System 之本地文件系统

    上一篇文章提到了,最近做一个基于 File System/IndexedDB的应用,上一篇是定额和使用的查询. 因为LocalFileSystem只有chrome支持,有点尴尬,如果按需加载又何来尴尬 ...

随机推荐

  1. utf8和utf8mb4的区别

    一.简介 MySQL在5.5.3之后增加了这个utf8mb4的编码,mb4就是most bytes 4的意思,专门用来兼容四字节的unicode.好在utf8mb4是utf8的超集,除了将编码改为ut ...

  2. 《Dotnet9》系列之建站-Dotnet9建站20天感悟

    本人站点 https://dotnet9.com,建站20天了,在这给站长朋友讲述个人建站经历,希望对大家能有所帮助. https://dotnet9.com 网站采用 宝塔 + WordPress ...

  3. WinForm 无边框窗体改变尺寸及移动窗体

    #region 无边框窗体移动改变大小 [DllImport("user32.dll")] public static extern bool ReleaseCapture(); ...

  4. Flask 教程 第十章:邮件支持

    本文翻译自The Flask Mega-Tutorial Part X: Email Support 这是Flask Mega-Tutorial系列的第十部分,在其中我将告诉你,应用如何向你的用户发送 ...

  5. 剑指offer笔记面试题7----重建二叉树

    题目:输入某二叉树的前序遍历和中序遍历的结果,请重建该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如,输入前序遍历序列{1, 2, 4, 7, 3, 5, 6, 8}和中序遍历序列 ...

  6. JS---DOM---点击操作---part1---20个案例

    点击操作:------>事件: 就是一件事, 有触发和响应, 事件源 按钮被点击,弹出对话框 按钮---->事件源 点击---->事件名字 被点了--->触发了 弹框了---& ...

  7. Android Studio 使用Memory Monitor进行内存泄露分析

    在使用Android Studio进行内存泄露分析之前,我们先回顾一下Java相关的内存管理机制,然后再讲述一下内存分析工具如何使用. 一.Java内存管理机制 1. Java内存分配策略 Java ...

  8. Paint.NET软件分享

    date: 2019-07-26 下载链接 官网链接 这是一款类Photoshop的轻量级图片编辑软件,仅有8.7MB.不多说话,直接上链接. 百度网盘链接 提取码:v4b2 软件简介 (百度百科警告 ...

  9. Codeforces Round #607 (Div. 1)

    A. Cut and Paste 题解 在计算答案的时候,我们发现只需要知道这个字符串前\(l\) 个具体是啥就行了.所以对于每一组询问,我们暴力把这个字符串前\(l\) 的位都算出来,然后剩下的就推 ...

  10. C# 对 Excel 的相关操作

    C# 对Excel的操作 学习自: 教练辅导 C# 对Excel的读取操作 我们需要额外添加引用: References 搜索Excel 这样我们的基础就添加完成了. 并且在using 中添加: us ...