Linux 设置修改文件的扩展属性命令:chattr, lsattr

Linux 设置修改文件的扩展属性命令:chattr, lsattrlsattr lists the file attributes on a second extended file system.

大家好,欢迎来到IT知识分享网。

Linux 设置修改文件的扩展属性命令:chattr, lsattr

目录

一、命令描述

二、命令格式

三、命令帮助信息

四、命令选项

五、练习

一、命令描述

1、chattr:

作用:设置文件的扩展属性,并且能够提高系统的安全性。

2、lsattr:

作用:用于显示chattr设置的属性。

二、命令格式

1、chattr:

chattr [-RVf] [-+=aAcCdDeijsStTu] [-v version] files…

2、lsattr:

lsattr [-RVadlv] [files…]

三、命令帮助信息

1、chattr:

[root@localhost ~]# man chattr

————————————————-

NAME

chattr – change file attributes on a Linux file system

SYNOPSIS

chattr [ -RVf ] [ -v version ] [ mode ] files…

DESCRIPTION

chattr changes the file attributes on a Linux file system.

OPTIONS

-R Recursively change attributes of directories and their contents.

-V Be verbose with chattr’s output and print the program version.

-f Suppress most error messages.

-v version

Set the file’s version/generation number.

2、lsattr:

[root@localhost ~]# man lsattr

——————————————

NAME

lsattr – list file attributes on a Linux second extended file system

SYNOPSIS

lsattr [ -RVadv ] [ files… ]

DESCRIPTION

lsattr lists the file attributes on a second extended file system. See chattr(1) for a

description of the attributes and what they mean.

OPTIONS

-R Recursively list attributes of directories and their contents.

-V Display the program version.

-a List all files in directories, including files that start with ” . ” .

-d List directories like other files, rather than listing their contents.

-v List the file’s version/generation number.

四、命令选项

chattr:

  1. [ -R ]:递归设置指定目录及其目录下的所有文件和子目录的属性;
  2. [ -V ]:详细显示目录和文件的属性设置情况;
  3. [ + ]:增加某项属性;
  4. [ – ]:取消某项属性;
  5. [ = ]:设置文件或目录只具有哪些属性;
  6. [ a ]:只允许项文件追加数据,不允许任何进程覆盖重写文件的内容;
  7. [ A ]:设置不允许系统更新文件的最后访问时间;
  8. [ i ]:不可修改属性。具有该属性的文件不能被删除、更名或修改其内容;
  9. [ c ]:压缩属性,写入或读取时,系统会自动进行压缩或解压缩;
  10. [ s ]:安全删除属性。即在删除一个文件时,会使用0填充源文件所在的存储区,以使回复工具无法恢复出文件的内容;
  11. [ u ]:可恢复性的删除。对于具有该属性的文件,在删除时,系统会保留其数据块一遍以后能恢复该文件的内容。

lsattr:

  1. [ -a ]:列出目录中的所有文件(包括隐藏文件);
  2. [ -d ]:以与文件相同的方式列出目录的扩展属性;
  3. [ -R ]:以递归的方式列出目录的属性及其内容。

五、练习

为了更好的掌握这些命令,接下来我们来一些简单的练习

练习一:将/root/c.txt文件设置为具有不可修改属性和不允许系统更新文件的最后访问时间属性,并查看设置后的属性。

[root@localhost ~]# chattr =ia /root/c.txt // [ i ]选项代表不可修改;[ a ]选项代表不允许更新文件的最后访问时间

[root@localhost ~]# lsattr /root/c.txt

—-ia———- /root/c.txt

Linux 设置修改文件的扩展属性命令:chattr, lsattr

练习一 5-1

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/61127.html

(0)
上一篇 2024-05-11 18:26
下一篇 2024-05-12 12:00

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信