在Linux下面删除文件报Operation not permitted
- 百度了一番,也有root干不了的事情,原来是是文件被保护了。用最高权限rm文件,居然报错Operation not permitted。查看权限也没有问题。可想而知有可能文件被保护了。用命令lsattr检查一下就知道。
列出被保护的文件
通过使用 [lsattr] 命令跟上想要删除的文件名或者文件夹一直按tab,就会把被保护的文件列出来我们看到了被保护的文件。如下
[root@localhost ~]# rm -rf /home/redshop/
rm: cannot remove `/home/redshop/redshop/public/.user.ini': Operation not permitted
[root@localhost ~]# lsattr /home/redshop/redshop/public/.user.ini
----i--------e- /home/redshop/redshop/public/.user.ini
解决方案,通过chattr命令解决
1,直接输入命令 [chattr] 按enter并不能直接解决问题,他只会把所有的受保护的文件都列出来。
[root@localhost ~]# chattr
anaconda-ks.cfg .bashrc install.log.syslog .rnd
.bash_history .composer/ lnmp-install.log .tcshrc
.bash_logout .cshrc .pearrc .viminfo
.bash_profile install.log .pki/ .Xauthority
[root@localhost ~]# chattr
anaconda-ks.cfg .bashrc install.log.syslog .rnd
.bash_history .composer/ lnmp-install.log .tcshrc
.bash_logout .cshrc .pearrc .viminfo
.bash_profile install.log .pki/ .Xauthority
[root@localhost ~]# chattr
anaconda-ks.cfg .bashrc install.log.syslog .rnd
.bash_history .composer/ lnmp-install.log .tcshrc
.bash_logout .cshrc .pearrc .viminfo
.bash_profile install.log .pki/ .Xauthority
2,在输入命令[chattr]的时候要跟上具体的文件所在目录,如下
[root@localhost ~]# chattr /home/redshop/redshop/public/.user.ini
Must use '-v', =, - or +
[root@localhost ~]# rm -rf /home/redshop/
rm: cannot remove `/home/redshop/redshop/public/.user.ini': Operation not permitted
为什么还是不行呢?这里在敲命令的时候要带上 chattr -i /home/redshop/redshop/public/.user.ini
[root@localhost ~]# chattr -i /home/redshop/redshop/public/.user.ini
[root@localhost ~]# rm -rf /home/redshop/
[root@localhost ~]# cd /home/
[root@localhost home]# ls
winner www wwwlogs wwwroot