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/