uTools-Manuals/docs/linux/chattr.html
2019-04-21 11:50:48 +08:00

29 lines
1.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<h1 id="chattr">chattr</h1>
<p>用来改变文件属性</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>chattr命令</strong> 用来改变文件属性。这项指令可改变存放在ext2文件系统上的文件或目录属性这些属性共有以下8种模式</p>
<pre><code class="language-bash">a让文件或目录仅供附加用途
b不更新文件或目录的最后存取时间
c将文件或目录压缩后存放
d将文件或目录排除在倾倒操作之外
i不得任意更动文件或目录
s保密性删除文件或目录
S即时更新文件或目录
u预防意外删除。</code></pre>
<h3 id="语法">语法</h3>
<pre><code class="language-bash">chattr(选项)</code></pre>
<h3 id="选项">选项</h3>
<pre><code class="language-bash">-R递归处理将指令目录下的所有文件及子目录一并处理
-v&lt;版本编号&gt;:设置文件或目录版本;
-V显示指令执行过程
+&lt;属性&gt;:开启文件或目录的该项属性;
-&lt;属性&gt;:关闭文件或目录的该项属性;
=&lt;属性&gt;:指定文件或目录的该项属性。</code></pre>
<h3 id="实例">实例</h3>
<p>用chattr命令防止系统中某个关键文件被修改</p>
<pre><code class="language-bash">chattr +i /etc/fstab</code></pre>
<p>然后试一下rm、mv、rename等命令操作于该文件都是得到Operation not permitted的结果。</p>
<p>让某个文件只能往里面追加内容,不能删除,一些日志文件适用于这种操作:</p>
<pre><code class="language-bash">chattr +a /data1/user_act.log</code></pre>
<!-- Linux命令行搜索引擎https://jaywcjlove.github.io/linux-command/ -->