Total Pageviews

Saturday 31 December 2011

linux中,改变文件属性的命令-chattr

Chattr according to Wikipedia;
“chattr is a Linux command that allows a user to set certain attributes on a file. Mostly chattr is used to make files immutable so that password files and certain system files cannot be erased during software upgrades.”
To set a file as immutable;
chattr +i file_name
To remove;
chattr -i file_name
http://en.wikipedia.org/wiki/Chattr

Chatter is a utility you’d find on most Linux systems, it’s sole purpose is to change file attributes.
when you use Chattr you’ll probably use it in symbolic mode, this means you will be using +, – and =(plus, minus and equals) plus either of the attributes: A, S, a, c, D, d, I, i, j, s, T, t, u.
Symbols
+ adds a attribute
- removes a attribute
= causes the attribute to be the only
Attributes
a (small A) is append only, this only allows someone to add to a file.
c (small C) is compressed
d (small D) is no dump
i (small I) is immutable, meaning no delete for anyone, not even root
j (small J) is journaling
s (small S) is secure deletion, incase you want to remove a file completely with no way of recovery(except IBAS)
t (small T) is no tailing
u (small U) is undeleteable
A (capital A) is no atime updates
D (capital D) is synchronousdirectory updates
S (capital S) is synchronous updates
T (capital T) is top of directory hierarchy, useful for important files
Options
As with most commands you got options as well
chattr got most of the common ones:
-R, recursive
-V, verbose
-f, suppress most errors
-v, version
options go first of course
Common use
most of the time you won’t use all of these options, but some you will run into quite often would be
chattr +i/chattr =i to protect files from accidental deletion
chattr +T to make a important file top of the file listings
chattr +d to prevent dumping of a file
and in some rare cases
chattr +ad to only allowing appending and prevent backup using
dump
, this could be useful for log files etc. that you only want to be appended to and not backed up
Source: man chattr
--------------------------------------
Linux下的文件属性修改指令chattr。
文章内容取自http://baike.baidu.com/view/2761030.htm

语法结构:chattr [-RV][-v<版本编号>][+/-/=<属性>][文件或目录...]

参数:
-R 递归处理,将指定目录下的所有文件及子目录一并处理。
-V 显示指令执行过程。
-v<版本编号> 设置文件或目录版本。
+<属性> 开启文件或目录的该项属性。
-<属性> 关闭文件或目录的该项属性。
=<属性> 指定文件或目录的该项属性。
备注:这项指令可改变存放在ext2、ext3、ext4、xfs、ubifs、reiserfs、jfs等文件系统上的文件或目录属性。(请注意vfat不可以!)

这些属性共有以下8种模式:
a:让文件或目录仅供附加用途。
b:不更新文件或目录的最后存取时间。
c:将文件或目录压缩后存放。
d:将文件或目录排除在倾倒操作之外。
i:不得任意更动文件或目录。
s:保密性删除文件或目录。
S:即时更新文件或目录。
u:预防意外删除。

No comments:

Post a Comment