How to deal with the prompt "Operation not permitted" when deleting files in Linux

How to deal with the prompt "Operation not permitted" when deleting files in Linux

Colleagues often ask, when deleting files/directories, an Operation not permitted error is reported. How to deal with this? !

This is usually a permissions issue, such as:

1. If you are a normal user with sufficient permissions, the folder may be used by other services/processes.

lsof +D /Dir/Your/Want/To/Delete/

First execute the above command to query the process IDs that call the folder, and then kill it. At this time, it should be possible to delete it!

2. If you are a normal user and lack permissions, you need to use the su or sudo command to delete the folder

3. If you are the root user and still get the above error, the file is likely locked

[root@linux ~]# lsattr YourFile
  ---i---------- YourFile

You need to use the lsattr command to check whether the system has added i, attributes, such as above. This parameter makes a file "cannot be deleted, renamed, set links, or have data written or added! It is of great help to system security! This command is also the reason why you cannot perform the deletion operation even if you are the root user. Then use the chattr command to remove the attribute

[root@linux ~]# chattr -i YourFile
[root@linux ~]# lsattr YourFile
[root@linux ~]#

Then you can delete the file!

Note: The i attribute of the chattr command is not suitable for all directories. The chattr command cannot protect the /, /dev, /tmp, and /var directories. Think about it: for example, in the /tmp directory, all users can create and delete their own temporary files, and the same is true for the root user. What will happen if even the root user cannot delete the files in this directory?

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Linux finds and processes files with spaces after the file name (two methods)
  • Linux file processing common command operation skills
  • Methods for processing various compressed files under Linux
  • Using winscp and batch processing under Windwos to upload files to Linux server through SSH port
  • How to enter directory/folder in Linux without using CD command
  • How to decompress multiple files using the unzip command in Linux
  • Detailed explanation of Linux one-line command to process batch files

<<:  mysql5.7 installation and configuration tutorial under Centos7.3

>>:  React Fiber structure creation steps

Recommend

43 Web Design Mistakes Web Designers Should Watch Out For

This is an article about website usability. The a...

HTML symbol to entity algorithm challenge

challenge: Converts the characters &, <, &...

Detailed explanation of CSS line-height and height

Recently, when I was working on CSS interfaces, I...

Docker image access to local elasticsearch port operation

Using the image service deployed by docker stack,...

Analysis of common usage examples of MySQL process functions

This article uses examples to illustrate the comm...

5 ways to migrate from MySQL to ClickHouse

Data migration needs to be imported from MySQL to...

CSS3 radar scan map sample code

Use CSS3 to achieve cool radar scanning pictures:...

Detailed explanation of how to use the Vue date time picker component

This article example shares the specific code of ...

Limiting the number of short-term accesses to a certain IP based on Nginx

How to set a limit on the number of visits to a c...

Complete steps to install Anaconda3 in Ubuntu environment

Table of contents Introduction to Anaconda 1. Dow...

How to configure user role permissions in Jenkins

Jenkins configuration of user role permissions re...