In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to delete files with special names in linux. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Linux file naming rules we all know, in linux to delete a file can use the rm command, but there are some special names of files using the ordinary rm method can not be deleted, the following describes a variety of ways to delete special name files in linux.
Before the introduction, let's briefly explain the file naming conventions in linux. The file or directory name consists of any sequence of ASCII characters except "/" and the empty character "\ 0". Of course, many operating systems allow more types of characters to form file names. However, for us, it is not recommended to use some special characters to name files. Unfortunately, we may inadvertently create files with special names, or the program may accidentally create files made up of special characters, and it seems that deleting them is not as easy as we might think.
Delete with the path
Suppose you have a file called-static, which we delete in the normal way:
Rm-staticrm: invalid option-- 's'Try' rm. /-static' to remove the file'- static'.Try'rm-- help' for more information.
Unfortunately, this method prompts an error and does not successfully delete the-static file. Why is that? We know that in linux, it usually starts with -, followed by some characters, as an option for a command, and unfortunately,-static is considered by the rm command as a parameter option, and unfortunately, it does not actually have this option, so it eventually prompts invalid option -'s deletion, resulting in the-static file cannot be deleted.
So is there any way to delete it? We noticed that in addition to prompting illegal options, let's try rm. /-static, is that OK? Let's try this:
$rm. /-static$
It turns out that we successfully deleted the-static file. So the first way to get to us is to delete the file with the path.
Use-when deleting
In addition to prompting us to use rm. /-static, let's use rm-help to get more information, so let's take a look:
$rm-- help (omit part) To remove a file whose name starts with a'-', for example'--foo',use one of these commands: rm-foo rm. /-foo (omit part)
There are a lot of content, but you can note that for files that start with -, there are two ways to delete them, the second is mentioned earlier, and the second is to add-before the deleted file:
$rm-static$
We found that files that start with-can also be deleted in this way.
Use quotation marks when deleting
How to delete files composed of special characters, such as! *, etc. For example:
$rm\! * rm: missing operandTry'rm-help' for more information.
For this type of file, we need to enclose the file name in quotation marks:
$rm "\! *" $
In this way, it can be deleted, but this method does not apply to all files of this type. For example, a file named! * cannot be deleted in this way, because! * has other meanings. For more information, please see "linux"! Do you know the use of wonder? "
Add escape characters to delete files
Since! * cannot be deleted by adding quotation marks, is there any other way? Yes! When deleting, add escape characters:
$rm\! * $
So that it can be deleted. In linux, many characters have a special meaning, so when you need to use it as a normal character, you need to precede it with the\ escape character, which is similar to the escape in C language. For another example, to delete an abc file that begins with a space, you can use the following ways:
$rm\ abc$
It can be deleted successfully.
Delete according to I node number
In many cases, file names cannot be entered at all because they are a pile of garbled codes. Therefore, it is completely impossible to delete it through the method described above, is there any other way? Yes! Delete according to the I node by looking for the I node of the file.
For example:
$ls-I # find the I node number of the garbled file 1703907?. Pdf $find. /-inum 1703907-exec rm {}\; # or use the-delete parameter
For more information about the usage of find commands, please refer to "Advanced usage of find commands". This deletion through the I-node number applies to any of the previously mentioned types of files.
Here is an extension of a few words. How does it recognize a file in the operating system? It does not identify different files by file name, but by an iNode number, that is, I node number, and the file name is just one of the attributes of the file.
Delete using wildcard characters
Not much explanation:
$rm * .pdf$
However, this method may be mistakenly deleted, because as long as the file name ends with .pdf, it will be deleted, so it is used cautiously according to the actual situation.
There are many ways to delete special file names, which can be summarized as follows:
Delete with the path
Use-when deleting
Use quotation marks when deleting
Use escape characters to assist with deletion
Delete according to I node number
Delete using wildcard characters
Different types of files can be deleted in a more convenient way mentioned above.
On the linux to delete special name files in a variety of ways 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.
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.