在Linux下面删除文件报Operation not permitted

在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

通过以上步骤就成功的删除啦。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值