How Linux removes files that start with special characters

Source: Internet
Author: User

  Zhanhailiang Date: 2014-11-18

When using some tools, Linux often generates some files that start with a special character, such as-starting with a normal RM, which prompts "invalid option":

[Root@~]# RM-\,trail\:-Rm:invalid option-- ', 'Try`RM./-,trail:-' To remove the file '-,trail:-'. Try`RM --help' For more information.

This is because the Linux shell defaults to the-o|–option representation of the option configuration and cannot read the corresponding option configuration in the current command RM, so an error is given.

By rm–help you can see:

To remove afileWhose name starts with a`-' For example '-foo ', use one of these commands:RM -- -fooRM./-foo

In summary, to remove special files, you can use either an absolute path or a relative path or – to avoid mistakenly parsing the file name to the option configuration , which provides a variety of operational scenarios:

The first type:rm–filename

[ root@  ~"  # RM---\,trail\:- rm:remove regular empty file  " -,trail:-< span class= "St_ H "style=" Color:rgb (255,0,0) ">"? 

second type: rm relative path

[ root@  ~"  # rm./-\,trail\:- rm:remove Regular empty file  " . /-,trail:-< span class=" St_h "style=" Color:rgb (255,0,0) ">"?  

third type: RM absolute Path

[ root@  ~"  # rm ~/-\,trail\:- rm:remove Regular empty file  "/ root/-,trail:-< span class= "St_h" style= "Color:rgb (255,0,0)" > "?  

A bit more in-depth analysis of source code:

First, download the source package:

[root@~/software] # wget http://down1.chinaunix.net/distfiles/coreutils-8.4.tar.gz

View SRC/RM.C Source code:


It is visible that RM directly complains when the parameter starts with a special character-and is not in the option configuration.

How Linux removes files that start with special characters

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.