Ubuntu 22.04.4 LTS (linux) 目录和文件 可以读写 不能删除

1 创建目录和文件

mkdir  testdir
touch  testfile1
touch  testfile2
#ls  -l
drwxrwxr-x 2 test test 4096 Jul 15 15:45 testdir
-rw-rw-r-- 1 test test    0 Jul 15 15:45 testfile1
-rw-rw-r-- 1 test test    0 Jul 15 15:45 testfile2

2 修改权限

sudo  chattr +a  testfile1
sudo  chattr +a  testfile2
#查看
lsattr testfile*
-----a--------e------- testfile1
-----a--------e------- testfile2
#追加写入内容
echo "hi" >> testfile1
#cat testfile1 
hi
#测试删除文件
rm  testfile1
rm: cannot remove 'testfile1': Operation not permitted
#取消权限
sudo  chattr -a  testfile1
sudo  chattr -a  testfile2
#目录配置不能删除权限
sudo  chattr +a  -R   testdir/
#创建目录
mkdir  -p  testdir/test
#测试删除
rm  -rf  testdir/test/
rm: cannot remove 'testdir/test/': Operation not permitted
#取消目录权限
sudo  chattr -a  -R   testdir/

3 目录和文件 不能修改和删除

sudo  chattr +i  testfile1
#查看文件
lsattr testfile1
----i---------e------- testfile1
#写入文件测试
echo "hi" >> testfile1
bash: testfile1: Operation not permitted
#删除测试
rm  testfile1
rm: cannot remove 'testfile1': Operation not permitted
#取消权限
sudo  chattr -i  testfile1
#配置目录权限
sudo  chattr +i  -R  testdir/
#删除测试
rm   -rf  testdir/
rm: cannot remove 'testdir/': Operation not permitted
#取消目录权限
sudo  chattr -i  -R  testdir/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值