In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
What if the file in linux cannot be deleted? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Recently, our server was attacked by hackers, and then the properties of some files were modified so that we could not delete virus files, and even users with root could not delete them. Now record the solution.
The Linux file / folder cannot delete the problem solution
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 properties 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 property is set, the file is written to the hard disk synchronously (usually asynchronously)
After the u attribute is set, the data content 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 to the next level cd. # use the lsattr command directly to list the properties of all files and folders under the current folder. # do not use the syntax of the lsattr folder, which lists the properties of the files under the folder
Lsattr
If the folder is set, remove the properties of the folder, and then delete the files in the folder
Harvest
Although lsattr and chattr were found in the process of removing viruses, by understanding file attributes, we found that we can use file attributes to protect important files from being mistakenly deleted, and to ensure that files can be restored after erroneous deletion.
If there is no effect after the operation of the file, we can try to solve it from the folder.
After reading the above, have you mastered the solution that the files in linux cannot be deleted? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.