Linux can not delete files, modify the file attributes can not delete a solution

Source: Internet
Author: User

Scene:

When the company asks to uninstall the software, it also contains all the files in a directory. Then go to modify the shell script to delete files, add the deletion of files and folders command (of course, under the root permission)

such as: rm-rf/home/vito/****

But found running the shell script, dead and alive to delete files under that directory, of course, can not delete the directory, but also prompted----rm:cannot remove '/home/vito/****/xxx.xxx ': Permission denied.

Check on the Internet, said this case, is generally the file is set some non-deleted properties:

  

You can see the properties of the file by command lsattr filename, which can also be seen, this file has the I and a attribute, as to what these letters mean, you can refer to this connection

Http://www.cnblogs.com/JasonYangBlogs/p/4833896.html (although the English version can be seen through the Linux command: Man chattr, but the Chinese version is quicker to understand)

  A: After setting a, this file will only add data, not delete or modify the data, only root can set this property.

  I: It can make a file cannot be deleted, renamed, set the connection and cannot write or add data. Only root can set this property.

Therefore, after the file1 has these two hidden properties, the direct use of the RM command is unable to delete the file.

What to do, very simple, through the chattr command, modify the properties of the two files, you can delete the normal.

The command is: Chattr-ia./file1

    here '-' means to remove, in the same way, "+" indicates the properties of the set file ,

  

---------------------------------------------Split Line---------------------------------------------

New situation, you cannot delete a file even if you cancel a property that cannot be deleted

:

  

This is why, obviously delete to remove the file of the non-deleted attribute, how still can not delete the file, even the root user cannot delete, there are other users to delete it???

The answer is impossible, if even the root user can not delete the files, other users are more unlikely to delete, so can only be caused by other problems, then thought for a long time, has not understood why will not be deleted, the Internet did not find the answer, just like this has been consumed.

Later, when consulting others, see other people will look at the hidden properties of the folder, actually, will understand what is going on.

---------------------------------------------Split Line-------------------------------------------

Solution to the problem

In fact, the problem is simple, because the current file folder (directory) of the hidden property is not deleted, so when you want to delete the folder (directory) under the file, the system will also prompt the file is not deleted, insufficient permissions.

  

  

  File2 file under folder (directory) Dir1, although the File2 file has been removed from the non-deleted properties, but because its folder (directory) properties are not deleted, and eventually, file2 file can not be deleted!!!!

The solution is to put the current file in the folder (directory) {sometimes more than one folder (directory) is set to the non-deleted properties} of the non-deleted attributes can be removed, if there are multiple layers of folders (directories) have non-deleted attributes, it is necessary to ensure that each layer of non-deleted attributes are removed, Then you can delete the files that you've been unable to delete.

:

  

Summarize:

Thinking or should be more divergent, it logic is very clear, need to think of a person!

Linux can not delete files, modify the file attributes can not delete a solution

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.