linux Chattr,lsattr

本文介绍了如何利用Linux下的chattr命令设置文件属性,通过+i选项禁止文件被修改或删除,通过+a选项允许仅追加内容。展示了命令的实际操作过程及效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

两个命令主要是不允许别人修改、删除或者只允许添加,
应用实例。
[root@localhost test1]# chattr +i 1.txt
[root@localhost test1]# mv 1.txt 1
[root@localhost test1]# mkdir 1
[root@localhost test1]# mv 1.txt 1
mv: 无法将”1.txt” 移动至”1/1.txt”: 不允许的操作
[root@localhost test1]# lsattr 1.txt
—-i——–e- 1.txt
//只能给文件增加内容不能修改。
[root@localhost test1]# chattr +a 1.txt
[root@localhost test1]# lsattr 1.txt
—-ia——-e- 1.txt
[root@localhost test1]# rm 1.txt
rm:是否删除普通空文件 “1.txt”?
[root@localhost test1]# rm 1.txt
rm:是否删除普通空文件 “1.txt”?y
rm: 无法删除”1.txt”: 不允许的操作
[root@localhost test1]#

lsattr [ -RVadv ] [ files… ]
-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 [ -RVf ] [ -v version ] [ mode ] files…
-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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值