In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to delete files with special names in Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Naming rules for linux files
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-static rm: 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 not being 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 the above mentioned, and the second is to add-- in front of 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 operand Try'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.
The above is all the contents of the article "how to delete files with special names in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.