今天遇到一个修改文件时报错“Permission denied”,具体如下:
> ls
> test.txt
> echo world >> test.txt
-bash: test.txt: Permission denied
查看是否有权限
> ll
-rw-r--r-- 1 root root 6 Jun 28 17:18 test.txt
明明有rw权限,而且当前用户为root,却还是报错。
这可能是文件属性加了防修改设置,确认及修改如下
lsattr test.txt
----i--------e-- test.txt # 有个i,就是防修改的
chattr -i test.txt #去掉属性
lsattr test.txt #确认
-------------e-- test.txt
再修改文件
> echo world >> test.txt
> cat test.txt
hello
world
完成。