用 lsattr 查看文件属性

删除或修改文件总报“Operation not permitted”?先看看是不是被加了不可变属性。

Linux文件权限属性低风险
执行 lsattr 文件名 查看属性标志——出现 i 表示不可变(任何修改都被拒绝),a 表示只能追加。

01命令

命令
$ lsattr -a /etc/passwd

02作用说明

ext4 等文件系统在权限位之外还记录每文件属性:i(不可变)、a(只可追加)、A(不更新访问时间)、j(强制日志)等。lsattr 以标志串打印它们——当 rm、chmod 甚至 root 都遇到 'Operation not permitted' 时,第一步就是查它。对应的 chattr 用于设置或清除这些标志。

03风险

风险低风险
使用条件e2fsprogs package (preinstalled on distros using ext4). Only meaningful on ext2/ext3/ext4/xfs-style attributes; on tmpfs or NFS it errors or shows nothing.
!注意: root 也删不掉文件,多半是 i 属性在作怪:用 sudo chattr -i 文件名 清除(维护完记得加回,比如被工具保护的 /etc/resolv.conf)。在不支持属性的文件系统上 lsattr 会报错,这不代表文件损坏。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • lsattr(1) — Debian bookworm
    Debian Manpages · community · 2026-09-17
    依据: SYNOPSIS lsattr [ -RVadlpv ] [ files... ] — list file attributes on a second extended filesystem, with -a for hidden files too.
  • lsattr(1) — Arch Manual Pages
    Arch Linux · community · 2026-09-17
    依据: Same tool documented: lists the attributes of files on second extended filesystems, options -R -V -a -d.

最后验证: 2026-09-19 · 分类: 文件与文件夹

06相关方案