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

Win10 configuration tomcat environment variables tutorial diagram

Before configuration, we need to do the following...

Example of creating circular scrolling progress bar animation using CSS3

theme Today I will teach you how to create a circ...

JavaScript function call classic example code

Table of contents JavaScript function call classi...

Tomcat first deployment web project process diagram

Put your own web project in the webapps directory...

Implementation of the login page of Vue actual combat record

Table of contents 1. Preliminary preparation 1.1 ...

About converting textarea text to html, that is, carriage return and line break

Description: Change the carriage return in the tex...

Difference between var and let in JavaScript

Table of contents 1. Scopes are expressed in diff...

Detailed tutorial on how to install mysql8.0 using Linux yum command

1. Do a good job of cleaning before installation ...

Vue implements a simple shopping cart example

This article example shares the specific code of ...

A brief discussion on Nginx10m+ high concurrency kernel optimization

What is high concurrency? The default Linux kerne...

Simple use of Vue bus

Simple use of Vue bus Scenario description: Compo...

MySQL 5.5.56 installation-free version configuration method

The configuration method of MySQL 5.5.56 free ins...

How to deploy nginx with Docker and modify the configuration file

Deploy nginx with docker, it's so simple Just...

Top 10 useful and important open source tools in 2019

In Black Duck's 2017 open source survey, 77% ...