linux复制文件属性不变例子,linux中文件系统属性chattr权限

一.chattr命令格式

格式

chattr [+-=][选项] 文件或目录名

操作

+: 增加权限

-: 删除权限

=: 等于某权限

选项

i:

如果对文件设置i属性,那么不允许对文件进行删除/改名,也不能添加和修改数据;(相当于锁死文件,什么操作都不允许进行,对root用户也生效)

如果对目录设置i属性,那么只能修改目录下文件的数据,但不允许建立和删除文件.

a:

如果对文件设置a属性,那么只能在文件中增加数据,但是不能删除也不能修改数据;(相当于锁死文件中现有的数据,只能添加新的数据[不能使用vi或vim,只能使用>>],其他的操作都不允许进行,对root生效)

如果对目录设置a属性,那么只允许在目录中建立和修改文件,但是不允许删除.

实例

## 文件添加i属性

[root@izm5e2q95pbpe1hh0kkwoiz tmp]# touch test

[root@izm5e2q95pbpe1hh0kkwoiz tmp]# echo 111 >> test

[root@izm5e2q95pbpe1hh0kkwoiz tmp]# cat test

111

[root@izm5e2q95pbpe1hh0kkwoiz tmp]# chattr +i test

# i代表i属性,e代表文件是在ext文件系统下建立的

[root@izm5e2q95pbpe1hh0kkwoiz tmp]# lsattr -a test

----i--------e-- test

[root@izm5e2q95pbpe1hh0kkwoiz tmp]# echo 222 >> test

-bash: test: Permission denied

[root@izm5e2q95pbpe1hh0kkwoiz tmp]# rm -rf test

rm: cannot remove ‘test’: Operation not permitted

## 文件夹添加i属性

# 创建文件夹test

[root@izm5e2q95pbpe1hh0kkwoiz tmp]# mkdir test

# 在test文件夹下新建文件aaa

[root@izm5e2q95pbpe1hh0kkwoiz tmp]# touch test/aaa

[root@izm5e2q95pbpe1hh0kkwoiz tmp]# ls test

aaa

# 给文件夹test添加i属性

[root@izm5e2q95pbpe1hh0kkwoiz tmp]# chattr +i test

# test文件夹有i属性,aaa没有i属性

[root@izm5e2q95pbpe1hh0kkwoiz tmp]# lsattr -a test

----------I--e-- test/..

----i--------e-- test/.

-------------e-- test/aaa

# 文件aaa可以编辑

[root@izm5e2q95pbpe1hh0kkwoiz tmp]# echo 111 >> aaa

# 在test文件夹下不可以新建文件

[root@izm5e2q95pbpe1hh0kkwoiz tmp]# touch test/abc

touch: cannot touch ‘test/abc’: Permission denied

# 在删除test文件夹下的aaa没有权限

[root@izm5e2q95pbpe1hh0kkwoiz tmp]# rm -rf test/aaa

rm: cannot remove ‘test/aaa’: Permission denied

## 文件添加a属性

二.查看文件系统属性

格式

lsattr 选项 文件名

选项

-a: 显示所有文件和目录

-d: 若目标是目录,仅列出目录本身的属性,而不是子文件

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值