Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The solution to the problem that files can not be deleted in linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article uses easy-to-understand examples to introduce linux files can not be deleted solutions, the code is very detailed, interested friends can refer to, I hope you can help.

Normal deletion

If the file belongs to the current user, you can delete it using the rm command

Rm-rf file.sh

If it cannot be deleted, try to delete it using the root user, and if it cannot be deleted, please see the instructions below.

Commands you need to know

If the normal deletion method does not work, then we need to know the following command to delete

Lsattr

The lsattr command is used to display the properties of a file, as follows

# list the attributes of file.sh files lsattr file.sh# lists the attributes of all files and folders in the current directory lsattr

Attribute description

After setting the I property, the file cannot be deleted or renamed, and the setting connection cannot write or add data, which can only be set by root users.

After the a property is set, the file can only add data, neither delete nor modify the data. Only root users can set it.

After A property is set, if you access this file or directory, its access time atime will not be modified, which can avoid excessive access to the disk by slower machines. This is helpful for slower computers.

After the s property is set, if the file is deleted, it will be deleted completely from the hard disk

After the S attribute is set, the file is written synchronously to the hard disk (usually asynchronous). After the u attribute is set, the data content of the file is still stored on disk after the file is deleted, and the file can be recovered.

E represents that the file is executable

Chattr

Chattr is used to modify file attributes. Please switch to root user for this command. If you are a ubuntu user, you can modify it by adding sudo before the command.

# add I logo for file.sh file chattr + I file.sh# for file.sh file remove I tag chattr-I file.sh# add I for file.sh, a two IDs chattr + ia file.sh# remove I for file.sh files, a two IDs chattr-ia file.sh

Actual operation

We learned from the above that we cannot delete the file when we set any of the I and an attributes, so we first remove the I, an attributes, and then perform the deletion:

# remove I, an attributes chattr-ia file.sh# to check whether the lsattr file.sh# removal file rm-rf file.sh has been removed successfully

If the file has not been deleted successfully, we need to consider whether the folder to which the file belongs has the I or an attribute set (which is really hard to find)

# return cd to the next level. # use the lsattr command directly to list the attributes of all files and folders under the current folder. # do not use syntax such as the lsattr folder, which lists the attributes lsattr of the files under this folder

If the folder is set, remove the properties of the folder, and then delete the files in the folder

On the linux files can not be deleted solutions to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report